Haskell prime test

后端 未结 5 609
醉梦人生
醉梦人生 2021-01-02 12:52

I\'m new to Haskell, and I\'m trying a bit:

isPrime :: Integer->Bool
isPrime x = ([] == [y | y<-[2..floor (sqrt x)], mod x y == 0])

I

5条回答
  •  南笙
    南笙 (楼主)
    2021-01-02 13:38

    1. I think WinHugs needs to import a module for Integer and etc... Try Int
    2. The interpreter will not compute anything until you call e.g. isPrime 32 then it will lazily compute the expression.

    PS your isPrime implementation is not the best implementation!

提交回复
热议问题