Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

haskell - Cannot parse data constructor in a data/newtype declaration: [Either Int Int]

Tags:

haskell

I'm trying to declare a datatype that is a list of Either types.

data EitherInts = [Either Int Int]

But when I try to compile this type I get an error:

Cannot parse data constructor in a data/newtype declaration: [Either Int Int]

I have no idea why. What am I doing wrong?

like image 858
dopatraman Avatar asked Mar 06 '16 05:03

dopatraman


1 Answers

data is for defining new algebraic data types, which must each have their own constructor(s). So you could write

data EitherInts = EitherInts [Either Int Int]

But you probably don't mean this: you want some kind of type synonym. The simplest would be a type alias:

type EitherInts = [Either Int Int]

which acts exactly like [Either Int Int] - it's just a new, abbreviated name for that existing type.

like image 106
amalloy Avatar answered Sep 28 '22 03:09

amalloy