3
我有一些困難,找出爲什麼下面的代碼不起作用。我期望,因爲Command
數據類型是ServerCommand
或ClientCommand
任何類型的構造函數,預計Command
將能夠接受一個或另一個。我似乎對這些數據類型應該如何排隊有一個基本的誤解。Haskell類型混淆;無法匹配預期的類型,無論是/或關係
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!"))
當我嘗試這種代碼加載到ghci中,我得到以下錯誤:
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.