Skip to main content

Home/ Haskell/ Group items tagged backtracking

Rss Feed Group items tagged

Javier Neira

Monads in 15 minutes: Backtracking and Maybe - 0 views

  • type Choice a = [a] choose :: [a] -> Choice a choose xs = xs
  • Because Haskell doesn’t compute answers until we ask for them, we get the actual backtracking for free!
  • The missing function is almost too trivial to mention: Given a single value of type a, we need a convenient way to construct a value of type Choice a:
  • ...5 more annotations...
  • More math trivia: return is also known as unit and η. That’s a lot of names for a very simple idea.)
  • makePairs = choose [1,2,3] >>= (\x -> choose [4,5,6] >>= (\y -> return (x,y)))
  • makePairs' = do x <- choose [1,2,3] y <- choose [4,5,6] return (x,y)
  • Every monad has three pieces: return, map and join.
  • Backtracking: The lazy way to code
1 - 1 of 1
Showing 20 items per page