Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
2.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

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{..}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...