Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arrow (->) as haskell data constructor

Tags:

haskell

I'm confused about the arrow and what it actually means in the data constructor. I'm surprised it even compiled but I have no idea how to use it.

If I try to use it as the name of a data constructor it doesn't parse, and I'm not sure how else to interpret it. If I interpret it as a function type then the data constructor has no name which also does not make sense to me.

data Type
  = TBool
  | TInt
  | Arrow Type Type
  | (->) Type Type

test :: Type 
test = Arrow TBool TInt -- Ok

test' :: Type
test' = (->) TBool TInt -- Parse Error on input '->'
like image 408
bobluza Avatar asked Jul 26 '19 04:07

bobluza


1 Answers

It does look like a GHC bug (thanks to Kevin Buhr for reporting it) in the use case you provided.

Note

This does fail to parse with GADTs:

data Type where
  TBool :: Type
  TInt :: Type
  Arrow :: Type -> Type -> Type
  (->) :: Type -> Type -> Type
like image 51
lehins Avatar answered Oct 21 '22 12:10

lehins