Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell, lacks an accompanying binding?

Tags:

haskell

this is my program (I realise it's not an entirely useful program):

data Temp a = Something1 | Something2 deriving (Show,Eq,Ord)

length :: Temp a -> Integer
Something1 = 0
Something2 = 1

and I keep getting the error message:

Haskellfile.lhs:3:3: The type signature for `length' lacks an accompanying binding (You cannot give a type signature for an imported value)

Can someone please help?

like image 250
user997112 Avatar asked Dec 28 '22 12:12

user997112


1 Answers

data Temp a = Something1 | Something2 deriving (Show,Eq,Ord)

length :: Temp a -> Integer
length Something1 = 0
length Something2 = 1

It's better to change length to something else, to avoid clash with Prelude's length. If you want to use your length as "default", add

import Prelude hiding (length)
import qualified Prelude

on the beginning, and refer to Prelude's version with Prelude.length. Not recommended.

By the way if your Temp doesn't depend on a, you might consider

data Temp = Something1 | Something2 deriving (Show,Eq,Ord)
like image 176
sdcvvc Avatar answered Jan 05 '23 00:01

sdcvvc