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/paf31 Jul 02 '15
Well, I think it's easier to read when they are on the left, but it changes the type checking subtly. In this case, it won't make a difference to the typing, but it could in general.