take :: Int -> [a] -> [a]
genericTake :: Integral i => i -> [a] -> [a]
I have read that the inconvenient type of take is due to historical reasons, and that changing it could cause some code to break.
But can't I replace take with genericTake everywhere without breaking anything? What's the problem?
A breaking case
genericTake :: Integral i => i -> [a] -> [a]
genericTake n xs = take (fromIntegral n) xs
class Foo a where
bar :: a -> String
instance Foo Int where
bar _ = "int"
foo :: String -> [a] -> [a]
foo ns xs = let y = read ns
z = bar y
in take y xs
This will break for genericTake.
No instance for (Foo i0) arising from a use of `bar'
The type variable `i0' is ambiguous
This is a cooked up example but you can understand some type inference occuring on the first argument of take where it is assumed that it is Int, now when you change type to Integral i => i some problems might occur as above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With