Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module provides a couple of basic function parameter types to be
used in Commands
function definitions. By implementing the
same typeclasses, one can create their own custom types to use instead
(or as well as) if they prefer.
- data Flag flags help a = Flag a
- data Value help a = Value a
- class FromString a where
- fromString :: String -> Either String a
Function Parameter Types
Use this type in a function embedded in a Command
in order to
require a flag. The type signature for this lists the flags that we
want to match against, the associated help text, and the output type
we want the flag to be cast to.
Flag
s of Maybe
or Bool
types have special handling:
if the flag doesnt exist for either of these types, we'll be
handed back a False
/Nothing
rather than get an error,
else if the flag does exist we'll get back a True
/Just val
.
Bool
flags are expected to be provided an empty string as the value;
if you care about the value but want it to be optional, use Maybe
.
Flag a |
KnownSymbol help => ParamHelp (Flag flags help a) Source | |
KnownSymbols flags => ParamFlags (Flag flags help a) Source | |
FromString a => ToParam (Flag flags help a) Source | |
ToParam (Flag flags help Bool) Source | |
FromString a => ToParam (Flag flags help (Maybe a)) Source |
Use this type in a function embedded in a Command
in order to
require a value. The type signature for this contains the associated
help text for the command, and the type we expect the value to be cast
to.
Value a |
KnownSymbol help => ParamHelp (Value help a) Source | |
ParamFlags (Value help a) Source | |
FromString a => ToParam (Value help a) Source |
Casting from String
class FromString a where Source
Typeclass used by Flag
and Value
to convert the provided string to
the desired haskell type. Anything that satisfies Read
will satisfy this,
but we can override the Read
behaviour as we see fit on a per type basis
by explicitly implementing this.
fromString :: String -> Either String a Source
FromString String Source | |
Read a => FromString a Source |