Skip to content

Instantly share code, notes, and snippets.

@hvr
Last active February 27, 2016 21:20
Show Gist options
  • Save hvr/cdc4996fde37814d1d10 to your computer and use it in GitHub Desktop.
Save hvr/cdc4996fde37814d1d10 to your computer and use it in GitHub Desktop.
module GenDev where
data Foo = Foo
{ foo :: String
, bar :: Maybe [Int]
, baz :: [Int]
} -- deriving Generic
instance Monoid Foo where
mempty = Foo mempty mempty mempty
a `mappend` b = Foo { foo = combine foo
, bar = combine bar
, baz = combine baz
}
where combine field = field a `mappend` field b
{- compiled with
ghc-7.10.3 -O1 -dsuppress-all -fforce-recomp -ddump-simpl -c ManDev.hs
==================== Tidy Core ====================
Result size of Tidy Core = {terms: 115, types: 197, coercions: 0}
bar
bar =
\ ds_dpS ->
case ds_dpS of _ { Foo ds1_dpT ds2_dpU ds3_dpV -> ds2_dpU }
baz
baz =
\ ds_dpW ->
case ds_dpW of _ { Foo ds1_dpX ds2_dpY ds3_dpZ -> ds3_dpZ }
foo
foo =
\ ds_dpO ->
case ds_dpO of _ { Foo ds1_dpP ds2_dpQ ds3_dpR -> ds1_dpP }
$w$cmappend
$w$cmappend =
\ w_svh w1_svi ->
(# case w_svh of _ { Foo ds_dpP ds1_dpQ ds2_dpR ->
++
ds_dpP
(case w1_svi of _ { Foo ds3_Xqk ds4_Xqm ds5_Xqo -> ds3_Xqk })
},
case w_svh of _ { Foo ds_dpT ds1_dpU ds2_dpV ->
case ds1_dpU of wild1_ar1 {
Nothing ->
case w1_svi of _ { Foo ds3_XqK ds4_XqM ds5_XqO -> ds4_XqM };
Just ipv_ar5 ->
case w1_svi of _ { Foo ds3_XqL ds4_XqN ds5_XqP ->
case ds4_XqN of _ {
Nothing -> wild1_ar1;
Just ipv1_arb -> Just (++ ipv_ar5 ipv1_arb)
}
}
}
},
case w_svh of _ { Foo ds_dpX ds1_dpY ds2_dpZ ->
++
ds2_dpZ
(case w1_svi of _ { Foo ds3_Xqs ds4_Xqu ds5_Xqw -> ds5_Xqw })
} #)
$fMonoidFoo_$cmappend
$fMonoidFoo_$cmappend =
\ w_svh w1_svi ->
case $w$cmappend w_svh w1_svi
of _ { (# ww1_svz, ww2_svA, ww3_svB #) ->
Foo ww1_svz ww2_svA ww3_svB
}
$fMonoidFoo_$cmempty
$fMonoidFoo_$cmempty = Foo ([]) (Nothing) ([])
Rec {
$wgo
$wgo =
\ w_svm ->
case w_svm of _ {
[] -> (# [], Nothing, [] #);
: y_aru ys_arv ->
$w$cmappend
y_aru
(case $wgo ys_arv of _ { (# ww1_svJ, ww2_svK, ww3_svL #) ->
Foo ww1_svJ ww2_svK ww3_svL
})
}
end Rec }
$fMonoidFoo_$cmconcat
$fMonoidFoo_$cmconcat =
\ w_svq ->
case $wgo w_svq of _ { (# ww1_svE, ww2_svF, ww3_svG #) ->
Foo ww1_svE ww2_svF ww3_svG
}
$fMonoidFoo
$fMonoidFoo =
D:Monoid
$fMonoidFoo_$cmempty $fMonoidFoo_$cmappend $fMonoidFoo_$cmconcat
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment