>>>flip fix (0 :: Int) (\\a b -> putStrLn \"abc\")
Output: \"abc\"
This is a simplified version of using flip fix
.
I saw t
This is just a funny way to write a recursive lambda, I can think of two possibilities why this is done:
You could rewrite the code much clearer like:
loop secret 0
where
loop secret numGuesses = do
putStr "Guess: "
guess <- getLine
let
score = calcScore secret guess
numGuesses' = numGuesses + 1
print score
case scoreRightPos score of
4 -> putStrLn $ "Well done, you guessed in " ++ show numGuesses'
_ -> loop secret numGuesses'
The difference being that you must pass the secret
manually, which is avoided by the recursive lambda (and this might be another reason to write it with fix
)
For a deeper understanding of fix, goog for "y-combinator"