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
1
u/peterjoel Jul 02 '15
Thanks. It actually makes sense when I think about it. And also explains why I didn't get a compile error - it was the JS code that was incorrect.