Last active
May 5, 2020 18:46
-
-
Save andreyk0/8a4c807e5feaf131c50dc8e07d9607b4 to your computer and use it in GitHub Desktop.
ghc pattern match
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 #-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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