|
|
|
|
|
by Arguggi
4073 days ago
|
|
This seems pretty similar to the Haskell Maybe Monad. "Learn You a Haskell for Great Good!" has an example[0]: routine =
case Just (0,0) of
Nothing -> Nothing
Just start -> case landLeft 2 start of
Nothing -> Nothing
Just first -> case landRight 2 first of
Nothing -> Nothing
Just second -> landLeft 1 second
becomes (using some 'do' syntactic sugar): routine = do
start <- return (0,0)
first <- landLeft 2
second <- landRight 2 first
landLeft 1 second
Checking for Nothing is taken care of 'automatically' and if any of start, first, second or (landLeft 1 second) are equal to Nothing routine is equal to Nothing too.[0] http://learnyouahaskell.com/a-fistful-of-monads#walk-the-lin... |
|