简体   繁体   中英

Getting started with purescript

I just started learning purescript following purescript by example but I am stuck at the end of Chapter2 using grunt project templates . I follow the instructions, but when I run the grunt command I get this error:

/Users/chad/playground/purescript/tests/tmp/node_modules/Control.Monad.Eff.Random/index.js:8
return Math.random();
            ^
TypeError: undefined is not a function
    at Object.random (/Users/chad/playground/purescript/tests/tmp/node_modules/Control.Monad.Eff.Random/index.js:8:17)
    at __do (/Users/chad/playground/purescript/tests/tmp/node_modules/Test.QuickCheck/index.js:177:52)
    at Object.__do (/Users/chad/playground/purescript/tests/tmp/node_modules/Main/index.js:19:201)
    at Object.<anonymous> (/Users/chad/playground/purescript/tests/tmp/index.js:1:79)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
Warning: -> error 1 /Users/chad/playground/purescript/tests/tmp/index.js (125ms) Use --force to continue.

Aborted due to warnings.

What I discovered by digging into the code is that the module Math gets imported into /output/Control.Monad.Eff.Random/index.js as

var Math = require("Math");

function random() {
    return Math.random();
}
;

If I remove the import, letting Math being native and running the main index.js simply with node index.js , everything works fine. I was wondering if there is something I can do to fix this in purescript, or if it is something I am doing wrong.

The purescript-random module is broken in the latest release when used with psc-make . It will be fixed by a compiler patch in the next release, 0.6.7, hopefully this week.

As a workaround, you should be able to specify the previous version of purescript-random in your bower.json file, or on the command line:

bower install purescript-random#0.1.1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM