Sep 29, 2010

More about monad haskell

Monad Whitespace

We can recognise one or more spaces by importing monads librerys. We can try by
this coding.
readExpr input = case parse (spaces >> symbol) "lisp" input of
Left err -> "No match: " ++ show err
Right val -> "Found value"

Return values
We can convert return valuer of some inputs. To do this we need to defined a data type which can store any data type. So for do that;

data LispVal = Atom String
| List [LispVal]
| DottedList [LispVal] LispVal
| Number Integer
| String String
| Bool Bool

This defineds a set of data types that the LispVal can hold.
Atom is a letter or a symbol which can be a charactor number or a symbol.

Generic monad
We can write our own monad thing by this way.

No comments:

Post a Comment

Your comments are always welcome ...