I would like to translate this java code into Frege Haskell:
PApplet pApplet = new PApplet();
System.out.print(pApplet.toString());
PApplet.runSketch(new String[]{"test"}, pApplet);
I did like this:
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
The part before maincompiles, but then I get these errors:
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: ()鈫抰1
E Process.fr:11: type error in expression 位p -> >>= p.toString (位pStr -> >> (putStrLn pStr) (runSketch (fromList ("test":[])) p))
type is : IO ()
expected: ()鈫抰1
E Process.fr:11: type error in expression >>= new (位p -> >>= p.toString (位pStr -> >> (putStrLn pStr) (runSketch (fromList ("test":[])) p)))
type is : ()鈫抰1
expected: IO ()
E Process.fr:11: type error in expression 位_ -> >>= new (位p -> >>= p.toString (位pStr -> >> (putStrLn pStr) (runSketch (fromList ("test":[])) p)))
type is : ()鈫抰1
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
I try to meet the compiler criteria, but to no avail. After innumerable random combinations, this fragment above seems to me the most reasonable. Do I need type instructions in a block do? I don鈥檛 understand why it p <- PApplet.newis valued at IO PApplet? and how to make a JArray.fromListrefund ArrayOf RealWorld String? Frege is wonderful, but the interoperability is quite complicated. Can I focus on it more examples on Frege github?
source
share