Better Records was Re: [Haskell-cafe] Type Directed Name
Resolution
Stephen Tetley
stephen.tetley at gmail.com
Fri Nov 12 17:14:40 EST 2010
On 12 November 2010 21:48, Jonathan Geddes <geddes.jonathan at gmail.com> wrote:
>
> I cringe to imagine what the equivalent is in current Haskell syntax.
> Anyone want to try it? Not me!
Perhaps not pretty - but it is regular and avoids Template Haskell an
manages for the few times I have records-in-records:
doubleInner3OfA :: A -> A
doubleInner3OfA =
(\s a -> s { inner1 = f1 a }) <*> inner1
where
f1 = (\s a -> s { inner2 = f2 a }) <*> inner2
f2 = (\s a -> s { inner3 = 2 * a }) <*> inner3
data A = A { inner1 :: B }
deriving (Eq,Show)
data B = B { inner2 :: C }
deriving (Eq,Show)
data C = C { inner3 :: Int }
deriving (Eq,Show)
t1 = A (B (C 1))
demo1 = doubleInner3OfA $ t1
More information about the Haskell-Cafe
mailing list