lib*_*dev 4 java haskell frege
我想把这个java代码翻译成Frege Haskell:
PApplet pApplet = new PApplet();
System.out.print(pApplet.toString());
PApplet.runSketch(new String[]{"test"}, pApplet);
Run Code Online (Sandbox Code Playgroud)
我到目前为止做了:
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
Run Code Online (Sandbox Code Playgroud)
部分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
Run Code Online (Sandbox Code Playgroud)
我正在努力满足编译器标准,但没有成功.在无数随机组合之后,上面的这个片段对我来说似乎是最合理的.我需要do块中的类型提示吗?我不明白为什么要p <- PApplet.new评估IO PApplet?以及如何JArray.fromList返回ArrayOf RealWorld String?弗雷格很棒,但互操作性非常艰巨.是否有可能在Frege github上有更多关注它的例子?
你有
ST s X
Run Code Online (Sandbox Code Playgroud)
而你想要的
X
Run Code Online (Sandbox Code Playgroud)
而你在IO,这不过是ST RealWorld
因此,最自然的解决办法是replce在=与<-该行
args = JArray.fromList ["test"]
Run Code Online (Sandbox Code Playgroud)
你定了!
当然,由于类型别名,整个故事有点困难:
type ArrayOf a x = Mutable a (JArray x)
type STMutable s a = ST s (Mutable s a)
Run Code Online (Sandbox Code Playgroud)
如果de-aliaser选择翻译
ST s (Mutable s (JArray String))
Run Code Online (Sandbox Code Playgroud)
回到
ST s (ArrayOf s String)
Run Code Online (Sandbox Code Playgroud)
你可能会看到它.
| 归档时间: |
|
| 查看次数: |
180 次 |
| 最近记录: |