Non-recursive binding allows me to shadow bound value, for instance:
b a = let norec a = a + 10 in a
here let norec
created by myself means a let
binding but not recursive.
This is extremely helpful when using record wildcards:
data MyRecord = MyRecord{ {- vary huuuuuge set of definitions -} }
foo MyRecord{..} = let norec field1 = field1 + 1
field2 = modify field2
{- some other modifications to the fields -}
in MyRecord{..}
Is that achievable? Or how do you deal with it in your cases?
Are record wildcards actually that useful here? The usual old way of doing things looks quite concise to me:
foo r = r { field1 = field1 r + 1, field2 = modify (field2 r) }
The direct answer to your question is that there is no non-recursive analog of let
in Haskell; though you can use the Identity
monad to sort of hack something into place:
foo MyRecord{..} = runIdentity $ do
field1 <- return (field1 + 1)
field2 <- return (modify field2)
return MyRecord{..}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With