Ugh. The following code fails to compile:
factorsOf number = [(x, quot number x) | x <- [2..toInteger $ floor $ sqrt number], number `mod` x == 0]
The following error is thrown:
- "No instance for (Floating Integer) arising from a use of `sqrt'"
Please help? I'm clearly not grokking Haskell coercion.
PS: Leaving off toInteger
compiles but throws a type-ambiguity error at runtime.
floor
takes a non-integer and returns an integer, no extra motions to do.sqrt
on the other hand can’t take an integer, it’s the very first step that breaks. – FrownyFrogprint
. – n. 1.8e9-where's-my-share m.