Haskell type confusion; Couldn't match the expected type despite either/or relationship

Viewed 69

I'm having some trouble figuring out why the below code isn't working. I would expect that since the Command data type is either a ServerCommand or a ClientCommand that any type constructor that is expecting a Command would be able to accept one or the other. I seem to have a fundamental misunderstanding of how these datatypes should be lining up.

data ClientCommand  =   SEND |
                        DISCONNECT |
                        CONNECT

data ServerCommand  =   CONNECTED |
                        MESSAGE |
                        RECEIPT |
                        ERROR

data Command        =   ServerCommand | ClientCommand

type Frame          =   (Command, Maybe String)

makeConnect :: Frame
makeConnect = (CONNECT, (Just "hello!"))

When I try to load this code into ghci, I get the following error:

GHCi, version 7.10.3: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( Frames.hs, interpreted )

Frames.hs:15:16:

    Couldn't match expected type ‘Command’
                with actual type ‘ClientCommand’
    In the expression: CONNECT
    In the expression: (CONNECT, (Just "hello!"))
Failed, modules loaded: none.
1 Answers
Related