TemplateHaskell - CurryN

Run Settings
LanguageHaskell
Language Version
Run Command
{-# LANGUAGE TemplateHaskell #-} import Curr $(genCurries 20) add5 (a, b, c, d, e) = a + b + c + d + e main = print $ curry5 add5 1 2 3 4 5
{-# LANGUAGE TemplateHaskell #-} module Curr (genCurries) where import Control.Monad (replicateM) import Language.Haskell.TH import Data.Traversable (for) curryN :: Int -> Q Exp curryN n = do f <- newName "f" xs <- replicateM n (newName "x") let args = map VarP (f:xs) ntup = TupE (map VarE xs) return $ LamE args (AppE (VarE f) ntup) genCurries :: Int -> Q [Dec] genCurries n = for [1..n] mkCurryDec where mkCurryDec ith = do cury <- curryN ith let name = mkName $ "curry" ++ show ith return $ FunD name [Clause [] (NormalB cury) []]
Editor Settings
Theme
Key bindings
Full width
Lines