- class (MonadUpdate s m, Update s m m, ChoiceStore s) => CFLP s m
- type CS = ChoiceStoreIM
- data UpdateT s m a
- class ChoiceStore s
- type Computation m a = Context CS -> ID -> Nondet CS (UpdateT CS m) a
- eval :: (CFLP CS m, Update CS m m', Data a) => Strategy m' -> (Context CS -> ID -> Nondet CS m a) -> IO [a]
- evalPartial :: (CFLP CS m, Update CS m m', Data a) => Strategy m' -> (Context CS -> ID -> Nondet CS m a) -> IO [a]
- evalPrint :: (CFLP CS m, Update CS m m', Data a, Show a) => Strategy m' -> (Context CS -> ID -> Nondet CS m a) -> IO ()
- type Strategy m = forall a. m a -> [a]
- depthFirst :: Strategy []
- data NormalForm
- data Nondet cs m a
- newtype Context cs = Context cs
- data ID
- initID :: IO ID
- withUnique :: With ID a => a -> ID -> Nondet (C ID a) (M ID a) (T ID a)
- class ChoiceStore cs => Narrow cs a where
- unknown :: (MonadUpdate cs m, Narrow cs a) => ID -> Nondet cs m a
- failure :: MonadPlus m => Nondet cs m a
- oneOf :: (MonadUpdate cs m, ChoiceStore cs) => [Nondet cs m a] -> Context cs -> ID -> Nondet cs m a
- (?) :: (MonadUpdate cs m, ChoiceStore cs) => Nondet cs m a -> Nondet cs m a -> ID -> Nondet cs m a
- withHNF :: Update cs m m => Nondet cs m a -> (HeadNormalForm cs m -> Context cs -> Nondet cs m b) -> Context cs -> Nondet cs m b
- caseOf :: Update cs m m => Nondet cs m a -> [Match a cs m b] -> Context cs -> Nondet cs m b
- caseOf_ :: Update cs m m => Nondet cs m a -> [Match a cs m b] -> Nondet cs m b -> Context cs -> Nondet cs m b
- data Match a cs m b
- class Typeable a => Data a
- nondet :: (Monad m, Data a) => a -> Nondet cs m a
- prim :: Data a => NormalForm -> a
- groundNormalForm :: Update cs m m' => Nondet cs m a -> Context cs -> m' NormalForm
- partialNormalForm :: (Update cs m m', ChoiceStore cs) => Nondet cs m a -> Context cs -> m' NormalForm
- class ConsRep a where
- cons :: MkCons cs m a b => a -> b
- match :: (ConsRep a, WithUntyped b) => a -> (Context (C b) -> b) -> Match t (C b) (M b) (T b)
- apply :: Update cs m m => Nondet cs m (a -> b) -> Nondet cs m a -> Context cs -> ID -> Nondet cs m b
- fun :: (Monad m, LiftFun f g, NestLambda g cs m t) => f -> Nondet cs m t
Documentation
class (MonadUpdate s m, Update s m m, ChoiceStore s) => CFLP s m Source
MonadPlus m => MonadUpdate s (UpdateT s m) | |
CFLP ChoiceStoreIM (UpdateT ChoiceStoreIM []) | |
MonadPlus m => Update s (UpdateT s m) m | |
MonadPlus m => Update s (UpdateT s m) (UpdateT s m) | |
MonadTrans (UpdateT s) | |
Monad m => Monad (UpdateT s m) | |
Show (HeadNormalForm cs (UpdateT cs [])) | |
MonadPlus m => MonadPlus (UpdateT s m) | |
Show a => Show (UpdateT s [] a) | |
Show (Nondet cs (UpdateT cs []) a) |
class ChoiceStore s Source
ChoiceStore ChoiceStoreIM |
eval :: (CFLP CS m, Update CS m m', Data a) => Strategy m' -> (Context CS -> ID -> Nondet CS m a) -> IO [a]Source
evalPartial :: (CFLP CS m, Update CS m m', Data a) => Strategy m' -> (Context CS -> ID -> Nondet CS m a) -> IO [a]Source
evalPrint :: (CFLP CS m, Update CS m m', Data a, Show a) => Strategy m' -> (Context CS -> ID -> Nondet CS m a) -> IO ()Source
depthFirst :: Strategy []Source
(Monad m, Data a) => MkCons cs m a (Nondet cs m t) | |
MkCons cs m b c => MkCons cs m (a -> b) (Nondet cs m t -> c) | |
With x (Nondet cs m a) | |
(cs ~ C a, m ~ M a, WithUntyped a) => WithUntyped (Nondet cs m b -> a) | |
NestLambda f cs m b => NestLambda (Nondet cs m a -> f) cs m (a -> b) | |
LiftFun (Nondet cs m b -> f) g => LiftFun (Nondet cs m a -> Nondet cs m b -> f) (Nondet cs m a -> g) | |
LiftFun (Nondet cs m a -> Context cs -> ID -> Nondet cs m b) (Lifted cs m a b) | |
LiftFun (Nondet cs m a -> ID -> Nondet cs m b) (Lifted cs m a b) | |
LiftFun (Nondet cs m a -> Context cs -> Nondet cs m b) (Lifted cs m a b) | |
LiftFun (Nondet cs m a -> Nondet cs m b) (Lifted cs m a b) | |
Show (Nondet cs (UpdateT cs []) a) | |
Show (Nondet cs [] a) | |
WithUntyped (Nondet cs m a) |
Context cs |
class ChoiceStore cs => Narrow cs a whereSource
ChoiceStore cs => Narrow cs Bool | |
(ChoiceStore cs, Narrow cs a) => Narrow cs [a] |
oneOf :: (MonadUpdate cs m, ChoiceStore cs) => [Nondet cs m a] -> Context cs -> ID -> Nondet cs m aSource
(?) :: (MonadUpdate cs m, ChoiceStore cs) => Nondet cs m a -> Nondet cs m a -> ID -> Nondet cs m aSource
withHNF :: Update cs m m => Nondet cs m a -> (HeadNormalForm cs m -> Context cs -> Nondet cs m b) -> Context cs -> Nondet cs m bSource
caseOf_ :: Update cs m m => Nondet cs m a -> [Match a cs m b] -> Nondet cs m b -> Context cs -> Nondet cs m bSource
The Data
class comprehends a fundamental primitive gfoldl
for
folding over constructor applications, say terms. This primitive can
be instantiated in several ways to map over the immediate subterms
of a term; see the gmap
combinators later in this class. Indeed, a
generic programmer does not necessarily need to use the ingenious gfoldl
primitive but rather the intuitive gmap
combinators. The gfoldl
primitive is completed by means to query top-level constructors, to
turn constructor representations into proper terms, and to list all
possible datatype constructors. This completion allows us to serve
generic programming scenarios like read, show, equality, term generation.
The combinators gmapT
, gmapQ
, gmapM
, etc are all provided with
default definitions in terms of gfoldl
, leaving open the opportunity
to provide datatype-specific definitions.
(The inclusion of the gmap
combinators as members of class Data
allows the programmer or the compiler to derive specialised, and maybe
more efficient code per datatype. Note: gfoldl
is more higher-order
than the gmap
combinators. This is subject to ongoing benchmarking
experiments. It might turn out that the gmap
combinators will be
moved out of the class Data
.)
Conceptually, the definition of the gmap
combinators in terms of the
primitive gfoldl
requires the identification of the gfoldl
function
arguments. Technically, we also need to identify the type constructor
c
for the construction of the result type from the folded term type.
In the definition of gmapQ
x combinators, we use phantom type
constructors for the c
in the type of gfoldl
because the result type
of a query does not involve the (polymorphic) type of the term argument.
In the definition of gmapQl
we simply use the plain constant type
constructor because gfoldl
is left-associative anyway and so it is
readily suited to fold a left-associative binary operation over the
immediate subterms. In the definition of gmapQr, extra effort is
needed. We use a higher-order accumulation trick to mediate between
left-associative constructor application vs. right-associative binary
operation (e.g., (:)
). When the query is meant to compute a value
of type r
, then the result type withing generic folding is r -> r
.
So the result of folding is a function to which we finally pass the
right unit.
With the -XDeriveDataTypeable
option, GHC can generate instances of the
Data
class automatically. For example, given the declaration
data T a b = C1 a b | C2 deriving (Typeable, Data)
GHC will generate an instance that is equivalent to
instance (Data a, Data b) => Data (T a b) where
gfoldl k z (C1 a b) = z C1 `k` a `k` b
gfoldl k z C2 = z C2
gunfold k z c = case constrIndex c of
1 -> k (k (z C1))
2 -> z C2
toConstr (C1 _ _) = con_C1
toConstr C2 = con_C2
dataTypeOf _ = ty_T
con_C1 = mkConstr ty_T "C1" [] Prefix
con_C2 = mkConstr ty_T "C2" [] Prefix
ty_T = mkDataType "Module.T" [con_C1, con_C2]
This is suitable for datatypes that are exported transparently.
Data Bool | |
Data Char | |
Data Double | |
Data Float | |
Data Int | |
Data Int8 | |
Data Int16 | |
Data Int32 | |
Data Int64 | |
Data Integer | |
Data Ordering | |
Data Word | |
Data Word8 | |
Data Word16 | |
Data Word32 | |
Data Word64 | |
Data () | |
Data a => Data [a] | |
(Data a, Integral a) => Data (Ratio a) | |
Typeable a => Data (Ptr a) | |
Typeable a => Data (ForeignPtr a) | |
Data a => Data (Maybe a) | |
Data a => Data (IntMap a) | |
(Data a, Data b) => Data (Either a b) | |
(Data a, Data b) => Data (a, b) | |
(Typeable a, Data b, Ix a) => Data (Array a b) | |
(Data a, Data b, Data c) => Data (a, b, c) | |
(Data a, Data b, Data c, Data d) => Data (a, b, c, d) | |
(Data a, Data b, Data c, Data d, Data e) => Data (a, b, c, d, e) | |
(Data a, Data b, Data c, Data d, Data e, Data f) => Data (a, b, c, d, e, f) | |
(Data a, Data b, Data c, Data d, Data e, Data f, Data g) => Data (a, b, c, d, e, f, g) |
prim :: Data a => NormalForm -> aSource
groundNormalForm :: Update cs m m' => Nondet cs m a -> Context cs -> m' NormalFormSource
partialNormalForm :: (Update cs m m', ChoiceStore cs) => Nondet cs m a -> Context cs -> m' NormalFormSource