Skip to content

Instantly share code, notes, and snippets.

@vvv
Created March 28, 2018 18:37
Show Gist options
  • Save vvv/aa1dd417d514937329cdf86b6ffb2d5d to your computer and use it in GitHub Desktop.
Save vvv/aa1dd417d514937329cdf86b6ffb2d5d to your computer and use it in GitHub Desktop.
Looking for idiomatic way to write expression with `Applicative`
#!/usr/bin/env stack
-- stack --resolver lts-11.2 script
{-# OPTIONS_GHC -Wall -W -Werror #-}
data Foo = Foo
{ fooInt :: Int
, fooBar :: Bar
} deriving Show
data Bar = Bar Baz
deriving Show
data Baz = Baz
{ bazInt :: Int
, bazChr :: Char
, bazStr :: String
} deriving Show
main :: IO ()
main = do
foo <- Foo <$> pure 42
<*> (Bar <$> (Baz <$> pure 13
<*> pure 'c'
<*> pure "whatever"
)
)
print foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment