Types: (Num a, Ord a) versus (Int a)?
haskell
Solution
Int is a type, not a typeclass. What you want is
myReplicate :: Int -> b -> [b]
or probably more precisely
myReplicate :: Int -> Int -> [Int]
Here is a good tutorial on types and typeclasses: http://learnyouahaskell.com/types-and-typeclasses
Problem
In a file, I'm trying to define a function like this: ``` myReplicate :: (Int a) => a -> b -> [b] myReplicate n x | n <= 0 = [] | otherwise = x : myReplicate (n-1) x ``` But when I try loading the file into ghci, I get this error: ``` ghci>:l 1.hs [1 of 1] Compiling Main ( 1.hs, interpreted ) 1.hs:38:17: `Int' is applied to too many type arguments In the type signature for `myReplicate': myReplicate :: Int a => a -> b -> [b] Failed, modules loaded: none. ``` ghci tells me that the type of myReplicate should be: ``` ghci>:t myReplicate myReplicate :: (Num a, Ord a) => a -> a1 -> [a1] ``` If I change the type declaration to what ghci recommends: ``` myReplicate :: (Num a, Ord a) => a -> b -> [b] ``` ...then the function compiles and 'works'. However, it 'works' like this: ``` ghci>myReplicate 3.2 1 [1,1,1,1] ``` Why can't I declare that myReplicate only takes an Int as the first argument (also in light of the fact that Int descends(?) from the Ord class)? I guess I could change my first guard to be x < 1, so that myReplicate 3.2 1 would produce [1, 1, 1,], but why do I have to bother with floats?