Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell type error using inferred type

Tags:

types

haskell

I created a data type to hold basic user information and loaded it into ghci. I then used ghci to look at the new data types type signature. I copied the type signature from ghci into the source file and tried to reload the file. Ghci threw an error.

The code and error are below.

My question is, why is this throwing an error. I used the type that was inferred by ghci.

User :: Int -> String -> String -> String -> String -> User
data User = User { userID :: Int,
                   login :: String,
                   password :: String,
                   username :: String,
                   email :: String
                   } deriving (Show)

Prelude> :r User [1 of 1] Compiling User ( User.hs, interpreted )

User.hs:3:0: Invalid type signature Failed, modules loaded: none.

like image 828
BlueBadger Avatar asked Dec 02 '22 06:12

BlueBadger


1 Answers

You may declare the type of a value (such as a function), but you may not declare the type of a data type or of a data constructor using the type declaration syntax for values. In fact, you already are declaring the full type of the data type and data constructor when you define them, so there is no need for an additional type declaration. So just leave out the line User :: ...; that line is a syntax error because it User with a capital U (constructor) and only lower-case names (values) may have ascribed types.

like image 138
yfeldblum Avatar answered Dec 04 '22 03:12

yfeldblum