0

When I type this code in Haskell:

data BT a = Empty | Fork a (BT a) (BT a) 
  Empty :: BT a
  Fork  :: a -> BT a -> BT a -> BT a

I get

error: parse error on input `::'

I can't see what the issue is though, if I add deriving (show) to the top line, it changes to

error: parse error on input `Empty'

2
  • 4
    What happens if you remove the last two lines? (In other words, why did you write them in the first place?) Commented Oct 25, 2022 at 0:06
  • 1
    The last two lines are already implicitly defined by Haskell since you gave the data definition. You must not include them. Commented Oct 25, 2022 at 0:19

1 Answer 1

6

Either write it using the "legacy" uniform datatype syntax:

data BT a = Empty | Fork a (BT a) (BT a)

or use equivalent GADT syntax

{-# Language GADTs #-}

data BT a where 
  Empty :: BT a
  Fork  :: a -> BT a -> BT a -> BT a

But not both :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.