r/purescript • u/peterjoel • Jul 01 '15
Just playing with Purescript examples. Why doesn't this work?
I took the FFI random example (in http://try.purescript.org/) and tried to add a parameter:
import Control.Monad.Eff
import Debug.Trace
foreign import data Random :: !
foreign import random
"function random( max ) {\
\ return Math.random() * max;\
\}" :: Number -> forall eff. Eff (random :: Random | eff) Number
main = do
let n = random 10
print nI don't get a compile error, but it produces a runtime error. The outputted code is:
var main = function __do() {
var _3 = random(10)();
return Debug_Trace.print(Prelude.showNumber)(_3)();
};It looks like it's calling the function twice, once unnecessarily with zero args.
What am I doing wrong?
2
Upvotes
View all comments
Show parent comment
2
u/paf31 Jul 02 '15
This. The value you give in the FFI needs to have the right representation for the type you picked, but it would be difficult to give a type to what you have now, using the types in the standard library at least.