以下は True を返します (2147483647 は素数であるため)。
length [f | f <- [2..(floor(sqrt 2147483647))], 2147483647 `mod` f == 0 ] == 0
以下のように拡張しようとすると機能しないのはなぜですか?
Prelude> [n | n <- [2..], length [f | f <- [2..(floor(sqrt n))], n `mod` f == 0 ] == 0 ]
<interactive>:1:39:
Ambiguous type variable `t' in the constraints:
`RealFrac t' arising from a use of `floor' at <interactive>:1:39-51
`Integral t' arising from a use of `mod' at <interactive>:1:56-64
`Floating t' arising from a use of `sqrt' at <interactive>:1:45-50
Probable fix: add a type signature that fixes these type variable(s)
よくわかりませんが、床の使用から RealFrac が発生するのはなぜですか? floor が RealFrac を取り、Integrals を作成したと思いましたか? さらに、上記の例に不満はありませんでした。そのときと同じように、より多くの整数を入力しているだけです。
Prelude> :t floor
floor :: (RealFrac a, Integral b) => a -> b