Created
August 31, 2016 16:04
-
-
Save sleexyz/a57ed2fd8762bb34cf5cd4a0f4082ad6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 RecordWildCards #-} | |
data Foo = Bar { a :: Int, b :: Int, c :: Int, d :: Int } | |
| Baz { x :: Int, y :: Int, z :: Int, w :: Int } | |
deriving (Show) | |
bar = Bar {a=1, b=2, c=3, d=4} | |
baz = Baz {x=10, y=20, z=30, w=40} | |
-- With record wildcards | |
-- | |
sum2 :: Foo -> Int | |
sum2 Bar{..} = a + b | |
sum2 Baz{..} = x + y | |
-- without record wildcards, I need to know the number of arguments: | |
sum2' :: Foo -> Int | |
sum2' f@(Bar _ _ _ _) = a f + b f | |
sum2' f@(Baz _ _ _ _) = x f + y f | |
-- I can mediate this problem probably with Pattern synonyms... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment