Skip to content

Instantly share code, notes, and snippets.

@aergus
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aergus/cdb8a9abc2fe30732036 to your computer and use it in GitHub Desktop.
Save aergus/cdb8a9abc2fe30732036 to your computer and use it in GitHub Desktop.
LamdaLisp (non-)example for failure of do notation
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