Created
April 13, 2012 12:42
-
-
Save xenophobia/2376657 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE TemplateHaskell, QuasiQuotes #-} | |
module THUtility where | |
import Language.Haskell.TH | |
import Control.Monad | |
import Control.Applicative | |
mapT :: Int -> ExpQ -> ExpQ | |
mapT count f = do | |
vars <- replicateM count $ newName "x" | |
lamE [tupP $ map varP vars] (tupE $ map (appE f . varE) vars) | |
mapMT :: Int -> ExpQ -> ExpQ | |
mapMT count f = do | |
vars <- replicateM count $ newName "x" | |
let ops = '(<$>):repeat '(<*>) | |
lamE [tupP $ map varP vars] $ foldl (\x -> \(op, y) -> (appE (appE (varE op) x) (appE f (varE y)))) (conE $ tupleDataName count) (zip ops vars) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment