Skip to content

Instantly share code, notes, and snippets.

@jandrewthompson
Created March 14, 2013 17:44
Show Gist options
  • Save jandrewthompson/5163467 to your computer and use it in GitHub Desktop.
Save jandrewthompson/5163467 to your computer and use it in GitHub Desktop.
Haskell Typeclasses
import Text.Printf(printf)
data Message =
Message {msgType :: String,
msgTo :: String,
msgValue :: String}
deriving (Eq, Read)
data FooMessage =
FooMessage {msg :: Message,
extraData :: String}
deriving (Eq, Read)
instance Show Message where
show m = printf "%s:%s:%s"
(msgType m) (msgTo m) (msgValue m)
instance Show FooMessage where
show m = printf "%s#%s"
(show (msg m)) (extraData m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment