
Hello, I want to use the FFT library in Haskell and for that I need to create an array. However, when I input array (1,100) [(i, i*i) | i <- [1..100]] in ghci, I get an error saying: No instance for (Enum e0) arising from the arithmetic sequence `1 .. 100' The type variable `e0' is ambiguous Possible fix: add a type signature that fixes these type variable(s) Note: there are several potential instances: instance Enum Double -- Defined in `GHC.Float' instance Enum Float -- Defined in `GHC.Float' instance Integral a => Enum (GHC.Real.Ratio a) -- Defined in `GHC.Real' ...plus 15 others In the expression: [1 .. 100] In a stmt of a list comprehension: i <- [1 .. 100] In the second argument of `array', namely `[(i, i * i) | i <- [1 .. 100]]' Could you please tell me how to add the type signature? -- Michal

2013/10/2 Michal Kawalec
Hello,
I want to use the FFT library in Haskell and for that I need to create an array. However, when I input
array (1,100) [(i, i*i) | i <- [1..100]]
Hi Michal, I think you should just add type signature to the [1..100], like this: array (1,100) [(i, i*i) | i <- ([1..100]::[Int])] Best, Karol

Excerpts from Karol Samborski's message of 2013-10-02 11:11:15 +0100:
I think you should just add type signature to the [1..100], like this: array (1,100) [(i, i*i) | i <- ([1..100]::[Int])]
Thank you, it seems that it worked, but with my limited knowledge of Haskell I stumbled onto another problem: Prelude Data.List Math.FFT Data.Array.CArray Data.Array.Base> array (1,100) [(i, i*i) | i <- [1..100]::[Int]] <interactive>:74:1: No instance for (IArray a0 Int) arising from a use of `array' The type variable `a0' is ambiguous Possible fix: add a type signature that fixes these type variable(s) Note: there are several potential instances: instance Foreign.Storable.Storable e => IArray CArray e -- Defined in `Data.Array.CArray.Base' instance IArray Array e -- Defined in `Data.Array.Base' instance IArray UArray Int -- Defined in `Data.Array.Base' Possible fix: add an instance declaration for (IArray a0 Int) In the expression: array (1, 100) [(i, i * i) | i <- [1 .. 100] :: [Int]] In an equation for `it': it = array (1, 100) [(i, i * i) | i <- [1 .. 100] :: [Int]] -- Michal

2013/10/2 Michal Kawalec
Excerpts from Karol Samborski's message of 2013-10-02 11:11:15 +0100:
I think you should just add type signature to the [1..100], like this: array (1,100) [(i, i*i) | i <- ([1..100]::[Int])]
Thank you, it seems that it worked, but with my limited knowledge of Haskell I stumbled onto another problem:
Prelude Data.List Math.FFT Data.Array.CArray Data.Array.Base> array (1,100) [(i, i*i) | i <- [1..100]::[Int]]
<interactive>:74:1: No instance for (IArray a0 Int) arising from a use of `array' The type variable `a0' is ambiguous Possible fix: add a type signature that fixes these type variable(s) Note: there are several potential instances: instance Foreign.Storable.Storable e => IArray CArray e -- Defined in `Data.Array.CArray.Base' instance IArray Array e -- Defined in `Data.Array.Base' instance IArray UArray Int -- Defined in `Data.Array.Base' Possible fix: add an instance declaration for (IArray a0 Int) In the expression: array (1, 100) [(i, i * i) | i <- [1 .. 100] :: [Int]] In an equation for `it': it = array (1, 100) [(i, i * i) | i <- [1 .. 100] :: [Int]]
-- Michal
This is because ghci doesn't know which instance of IArray to use. If you look at type signature of function 'array' you'll see that it returns some type 'a i e' where 'a e' is an instance of IArray class. So what you must do is simply tell it what 'a i e' you want. Try this: array (1,100) [(i, i*i) | i <- [1..100]] :: CArray Int Int Best, Karol

Excerpts from Karol Samborski's message of 2013-10-02 11:43:14 +0100:
This is because ghci doesn't know which instance of IArray to use. If you look at type signature of function 'array' you'll see that it returns some type 'a i e' where 'a e' is an instance of IArray class. So what you must do is simply tell it what 'a i e' you want. Try this:
array (1,100) [(i, i*i) | i <- [1..100]] :: CArray Int Int
Thank you for that explanation, it worked. -- Michal
participants (2)
-
Karol Samborski
-
Michal Kawalec