Skip to content

Instantly share code, notes, and snippets.

@akhileshs
Created February 10, 2016 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akhileshs/26d23e353b17d639f186 to your computer and use it in GitHub Desktop.
Save akhileshs/26d23e353b17d639f186 to your computer and use it in GitHub Desktop.
data Message = PlainText String | Encrypted String
send :: Message -> Recipient -> IO ()
send (Encrypted m) recipient = some magic with m
send (PlainText _) _ = undefined
data Maybe a = Just a | Nothing
-- movin' to phantom types
data Message a = Message String
data Encrypted
data PlainText
-- change send now
send :: Message Encrypted -> Recipient -> IO ()
encrypt :: Message PlainText -> Message Encrypted
decrypt :: Message Encrypted -> Message PlainText
newMessage :: String -> Message PlainText
newMessage s = Message s
-- this will get rejected by the type-checker
-- send (newMessage "hello!") "abc@xyz.com"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment