Haskell: Am I inventing the Monad list?

Complete Haskell newbie here, my apologies ....

I am trying to create a sequence of values ​​from another sequence and the resulting last value (so it’s not entirely clear to me how I will use the map).

In clojure, I would use a loop construct that is basically equivalent to a recursive function. So I thought I could use this problem with a recursive function along the lines

 genSequence :: [a] -> [b] -> [a] genSequence result [] = reverse result genSequence a:as b:bs = genSequence ((computeNextA ab):a:as) bs 

and I think it’s not so bad (the real function, of course, is more complicated ...), but I read about monads (read the excellent Philip Walder tutorial, then some things on monads in clojure) and cannot help but feel that I should use them here. Until now, my knowledge of monads has been purely theoretical, unfortunately, so I would be very grateful if you could help me.

+4
source share
1 answer

Not sure if this helps, but something like (assuming computeNextA is + )

 genSequence [4] [60,70,80,90] --[4,64,134,214,304] 

equivalently

 scanl (+) 4 [60,70,80,90] --[4,64,134,214,304] 
+4
source

Source: https://habr.com/ru/post/1385525/


All Articles