Skip to content

Instantly share code, notes, and snippets.

@mwotton
Created September 13, 2016 17:21
Show Gist options
  • Save mwotton/0255118a6b391361d43a9e190efdae04 to your computer and use it in GitHub Desktop.
Save mwotton/0255118a6b391361d43a9e190efdae04 to your computer and use it in GitHub Desktop.
{-# LANGUAGE TemplateHaskell #-}
import Data.Data
import qualified Data.Set as HS
import Data.Time
import Language.Haskell.TH.Syntax
foo :: (Data a) => a -> ()
foo _ = ()
table = $(do r <- runIO (HS.fromList . lines <$> readFile "/usr/share/dict/words")
[|r|] )
main = do
r <- HS.fromList . lines <$> readFile "/usr/share/dict/words"
print (foo r)
print $ HS.member "foo" table
@mwotton
Copy link
Author

mwotton commented Sep 13, 2016

class Lift t where
  -- | Turn a value into a Template Haskell expression, suitable for use in
  -- a splice.
  lift :: t -> Q Exp
  default lift :: Data t => t -> Q Exp
  lift = liftData

@mwotton
Copy link
Author

mwotton commented Sep 13, 2016

Am a bit confused by this - do I need to explicitly derive Lift for Data.Set? if so, what use is the defaulting in the Lift class?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment