Could I define an anonymous function without parameter in Haskell?
I have a block of code repeated in several branches. Those code refer to several values outside.
Purpose 0: Define a function do the job in the codeBlock.
Purpose 1: Don't repeat codeBlock twice.
Purpose 2: Don't pass d1..d4 to the function. Avoid passing file and time even better.
f event d1 d2 d3 d4 =
case event of
(Modified file time) -> do
codeBlock file time d1 d2 d3 d4
(Added file time) -> do
codeBlock file time d1 d2 d3 d44
_ -> return ()
let, i.e. you can turnx = case y of P1 -> f largeCodeBlock foo; P2 -> g bar largeCodeBlockintox = let lcb = largeCodeBlock in case y of P1 -> f lcb foo; P2 -> g bar lcb. Is this what you're after? (I'm happy to post this as an answer if yes.)where? Did you place it at the proper scope level? If not it may be in scope only for one of the case branches (its indentation must be the same as the word "case")