1{-# LANGUAGE TemplateHaskell, ScopedTypeVariables, TypeOperators, GADTs, EmptyDataDecls, PatternGuards #-}
2module Reflex.Dynamic.TH (qDyn, unqDyn) where
6import Language.Haskell.TH
8import Control.Monad.State
10-- | Quote a Dynamic expression. Within the quoted expression, you can use '$(unqDyn [| x |])' to refer to any expression 'x' of type 'Dynamic t a'; the unquoted result will be of type 'a'
14 let f :: forall d. Data d => d -> StateT [(Name, Exp)] Q d
16 Just (Refl :: d :~: Exp)
17 | AppE (VarE m) eInner <- d
19 -> do n <- lift $ newName "dyn"
23 (e', exprsReversed) <- runStateT (gmapM f e) []
24 let exprs = reverse exprsReversed
25 arg = foldr (\a b -> ConE 'FHCons `AppE` a `AppE` b) (ConE 'FHNil) $ map snd exprs
26 param = foldr (\a b -> ConP 'HCons [VarP a, b]) (ConP 'HNil []) $ map fst exprs
27 [| mapDyn $(return $ LamE [param] e') =<< distributeFHListOverDyn $(return arg) |]
29unqDyn :: Q Exp -> Q Exp
30unqDyn e = [| unqMarker $e |]
32-- | This type represents an occurrence of unqDyn before it has been processed by qDyn. If you see it in a type error, it probably means that unqDyn has been used outside of a qDyn context.
35-- unqMarker must not be exported; it is used only as a way of smuggling data from unqDyn to qDyn
36--TODO: It would be much nicer if the TH AST was extensible to support this kind of thing without trickery
37unqMarker :: a -> UnqDyn
38unqMarker = error "An unqDyn expression was used outside of a qDyn expression"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list