Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Documentation
class Parseable a where Source
Class describing parseable values. Much like the Read
class.
Parseable Char | Parses a single character string. |
Parseable Float | |
Parseable Int | Parses an |
Parseable Integer | |
Parseable Word | Parses a |
Parseable String | Identity parser. Ex: @parse "abc" == (Just "abc", 1) |
Parseable () | |
Parseable a => Parseable (Maybe a) | Greedily parses a single argument or no argument. Never fails. |
Parseable a => Parseable (List a) | Greedily parses arguments item-wise. Never fails.
Example: |
(Parseable a, Parseable b) => Parseable (a, b) | |
(Parseable a, Parseable b, Parseable c) => Parseable (a, b, c) |
repeatedParse :: Parseable a => Int -> [String] -> (Maybe [a], Int) Source
Repeatedly applies parse
the given number of times, accumulating the results.
Useful for implementing new parsers.
Example:
data Point = Point Float Float Float instance Parseable Point where parse strs = case repeatedParse 3 strs of (Just [x,y,z], n) -> (Just (Point x y z), n)` (Nothing, n) -> (Nothing, n)