Haskell, is there a lack of accompanying binding?

this is my program (I understand that this is not a very useful program):

data Temp a = Something1 | Something2 deriving (Show,Eq,Ord) length :: Temp a -> Integer Something1 = 0 Something2 = 1 

and I get an error:

Haskellfile.lhs: 3: 3: A typical signature for `length 'has no accompanying binding (you cannot give a type signature for the imported value)

Can anybody help?

+4
source share
1 answer
 data Temp a = Something1 | Something2 deriving (Show,Eq,Ord) length :: Temp a -> Integer length Something1 = 0 length Something2 = 1 

It is better to change length to something else to avoid a collision with the Prelude length. If you want to use your length as "default", add

 import Prelude hiding (length) import qualified Prelude 

at the beginning and refer to the Prelude version using Prelude.length . Not recommended.

By the way, if your Temp is independent of a , you can consider

 data Temp = Something1 | Something2 deriving (Show,Eq,Ord) 
+10
source

All Articles