Last active
August 29, 2015 14:04
-
-
Save aergus/cdb8a9abc2fe30732036 to your computer and use it in GitHub Desktop.
LamdaLisp (non-)example for failure of do notation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main = | |
(_mapSearchR 0 ([] ([] 0) ([] 1)) 0) | |
-- _mapSearchR :: Eq a => a -> [[a]] -> Int -> (Int, Int) | |
-- after removing the commented brackets this works too: | |
_mapSearchR = | |
(\ x xss k -> | |
(IF (NIL xss) | |
(: -1 -1) | |
-- ( | |
{ i <- (_listSearchR x (CAR xss) 0); | |
(IF (<= 0 i) | |
(: i k) | |
(_mapSearchR x (CDR xss) (+ k 1)) | |
) | |
} | |
-- ) | |
) | |
) | |
-- this works: | |
-- (\ x xss k -> | |
-- (IF (NIL xss) | |
-- (: -1 -1) | |
-- ((\ i -> | |
-- (IF (<= 0 i) | |
-- (: i k) | |
-- (_mapSearchR x (CDR xss) (+ k 1)) | |
-- ) | |
-- ) (_listSearchR x (CAR xss) 0) | |
-- ) | |
-- ) | |
-- ) | |
-- _listSearchR :: Eq a => a -> [a] -> Int -> Int | |
_listSearchR = | |
(\ x xs k -> | |
(IF (NIL xs) | |
-1 | |
(IF (== (CAR xs) x) | |
k | |
(_listSearchR x (CDR xs) (+ k 1)) | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment