Skip to content

Instantly share code, notes, and snippets.

@andreyk0
Last active May 5, 2020 18:46
Show Gist options
  • Save andreyk0/8a4c807e5feaf131c50dc8e07d9607b4 to your computer and use it in GitHub Desktop.
Save andreyk0/8a4c807e5feaf131c50dc8e07d9607b4 to your computer and use it in GitHub Desktop.
ghc pattern match
{-# LANGUAGE PatternSynonyms #-}
module Foo where
newtype FooBar = FooBar String deriving (Eq, Show)
pattern Whoa :: FooBar
pattern Whoa = FooBar "whoa"
pattern Meah :: FooBar
pattern Meah = FooBar "meah"
{-# COMPLETE Whoa, Meah, FooBar #-}
module Main where
import Foo
import System.Environment
import Control.Monad
main :: IO ()
main = do
as <- getArgs
forM_ as $ \x ->
case FooBar x
of Whoa -> putStrLn "Whoa!"
-- Meah -> putStrLn "Meah!"
FooBar huh -> putStrLn huh
print Whoa
print (Whoa == FooBar "whoa")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment