[英]Interoperability with Java in Frege, especially in IO Monad
我想把这个java代码翻译成Frege Haskell:
PApplet pApplet = new PApplet();
System.out.print(pApplet.toString());
PApplet.runSketch(new String[]{"test"}, pApplet);
我到目前为止做了:
data PApplet = mutable native processing.core.PApplet
where
native new :: () -> IO PApplet
native toString :: PApplet -> IO String
native runSketch processing.core.PApplet.runSketch
:: ArrayOf RealWorld String -> PApplet -> IO ()
main _ = do p <- PApplet.new
pStr <- p.toString
putStrLn pStr
args = JArray.fromList ["test"]
runSketch args p
部分main
编译,但后来我得到这些错误:
E Process.fr:14: type error in expression fromList ("test":[])
type is : STMutable t1 (JArray String)
expected: ArrayOf RealWorld String
E Process.fr:15: type error in expression p
type is : IO PApplet
expected: PApplet
E Process.fr:12: type error in expression >>= p.toString (λpStr -> >> (putStrLn pStr) (runSketch (fromList ("test":[])) p))
type is : IO ()
expected: ()→t1
E Process.fr:11: type error in expression λp -> >>= p.toString (λpStr -> >> (putStrLn pStr) (runSketch (fromList ("test":[])) p))
type is : IO ()
expected: ()→t1
E Process.fr:11: type error in expression >>= new (λp -> >>= p.toString (λpStr -> >> (putStrLn pStr) (runSketch (fromList ("test":[])) p)))
type is : ()→t1
expected: IO ()
E Process.fr:11: type error in expression λ_ -> >>= new (λp -> >>= p.toString (λpStr -> >> (putStrLn pStr) (runSketch (fromList ("test":[])) p)))
type is : ()→t1
expected: IO ()
E Process.fr:12: can't find a type for p.toString `toString`
is neither an overloaded function nor a member of IO PApplet
我正在努力满足编译器标准,但没有成功。 在无数随机组合之后,上面的这个片段对我来说似乎是最合理的。 我需要在类型提示do
阻止? 我不明白为什么p <- PApplet.new
评估IO PApplet
? 以及如何使JArray.fromList
返回ArrayOf RealWorld String
? 弗雷格很棒,但互操作性非常艰巨。 是否有可能在Frege github上有更多关注它的例子?
你有
ST s X
而你想要的
X
你在IO
,这只不过是ST RealWorld
因此,最自然的解决方案是在行中用<-
重复=
args = JArray.fromList ["test"]
你定了!
当然,由于类型别名,整个故事有点困难:
type ArrayOf a x = Mutable a (JArray x)
type STMutable s a = ST s (Mutable s a)
如果de-aliaser选择翻译
ST s (Mutable s (JArray String))
回到
ST s (ArrayOf s String)
你可能会看到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.