Skip to content

Instantly share code, notes, and snippets.

@fmap
Created June 22, 2014 08:37
Show Gist options
  • Save fmap/7e424a1147ee3edbd988 to your computer and use it in GitHub Desktop.
Save fmap/7e424a1147ee3edbd988 to your computer and use it in GitHub Desktop.
{-# LANGUAGE TemplateHaskell #-}
import Language.Haskell.TH (ExpQ, Exp(LamE, VarE, TupE), Pat(VarP), newName)
tuple :: Int -> ExpQ
tuple n = do
x <- newName "x"
return $ LamE [VarP x] (TupE . replicate n $ VarE x)
-- $(tuple 3) "fnord" == ("fnord","fnord","fnord")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment