haskell,template-haskell,scotty
OK, so given the above list, I am assuming you are looking to something that is equivalent to writing the following by hand: {-! LANGUAGE OverloadedStrings #-} import Web.Scotty import Data.String main = scotty 3000 $ do middleware logStdoutDev get (fromString $ '/' : "hello") (text "hello") get (fromString $...
import Language.Haskell.TH.Syntax nilName = mkNameG DataName "ghc-prim" "GHC.Types" "[]" is an equivalent definition of nilName, even though it is ugly. It can be expanded to a form that admits to pattern matching yielding to nilName = Name (OccName "[]") (NameG DataName (PkgName "ghc-prim") (ModName "GHC.Types")) which is not nicer nor...
{-# LANGUAGE TemplateHaskell #-} module Test where import Language.Haskell.TH data Color = Red | Blue | Green myShow' :: Q [Dec] myShow' = return [FunD (mkName "myShow") [mkClause 'Red, mkClause 'Blue, mkClause 'Green]] where mkClause n = Clause [ConP n []] (NormalB $ LitE $ StringL $ nameBase n) []...
haskell,yesod,template-haskell,hamlet
Import Yesod.Core and Yesod.Core.Widget, they will provide the appropriate functions. Also note that they have a online version of the book. And generally if you see import errors, do a search on Hoogle and in most of the cases you are likely to find a solution there....
Only the definitions before the template haskell call are accessible in the scope. See this previous question on the same topic: Haskell: Template Haskell and the scope....
You can do this using two files: a "maker" file: Maker.hs: module Maker where {-# LANGUAGE TemplateHaskell #-} import Language.Haskell.TH maker items = do x <- newName "x" lamE [varP x] (caseE (varE x) (map (\(a,b) -> match (litP $ stringL a) (normalB $ litE $ integerL b) []) items))...
haskell,ghc,generic-programming,template-haskell,scrap-your-boilerplate
If you leave the recursion in your data type open you end up suffering an extra constructor everywhere, but can layer in annotations freely without changing most of your skeletal tree. data Hutton x -- non-recursive functor type = Int Int | Plus x x deriving Functor newtype Tie f...
haskell,template-haskell,deriving
The paper Invertible Syntax Descriptions: Unifying Parsing and Pretty Printing describes one particularly idiomatic solution. Your example looks like this, using the invertible-syntax package based on that paper: import Prelude hiding (Applicative(..), print) import Data.Maybe (fromJust) import Text.Syntax import Text.Syntax.Parser.Naive import Text.Syntax.Printer.Naive data TVShow = BobsBurgers | MrRobot | BatmanTAS...
Import your module into another one that has the QuasiQuotes LANGUAGE pragma turned on , and then use the syntax [sample||] to call it. Note that it needs to be in a separate module; you can't start using [sample||] in the same module as it is defined in. See e.g....
Both <$> and <*> are left associative. You are right associating them. You can build the expression so that the operators are left-associated instead. mkExp' :: ExpQ -> [Name] -> ExpQ mkExp' acc [] = acc mkExp' acc (name:names) = mkExp'' [| $(acc) <$> ZipList $(varE name) |] names where...
haskell,yesod,template-haskell
I haven't actually used the composite primary key feature myself, but this error makes sense to me. There's not obvious serialization to Text for arbitrary composite keys, and so persistent doesn't generate it for you. If you'd like to use a MovieId inside your URLs, you'll need to manually define...
haskell,syntactic-sugar,template-haskell
This is not using the $ application operator, but is involving a Template Haskell slice. Very roughly, widgetFile "home" is code which is run at compile time: it generates Haskell code, which is then compiled as usual. It's a form of metaprogramming in Haskell....
haskell,yesod,template-haskell
EDIT: Simple type signature parameterization example added I think there is a problem with function name binding in your mkDeleteHandler. I would try something like this for example (example simplified): mkHandler :: String -> String -> Q [Dec] mkHandler typeName funcName = do funDecl <- [d| funcName :: String ->...