Skip to content

Instantly share code, notes, and snippets.

@olligobber
Created February 10, 2021 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olligobber/c97e9c97a7a5c0a4224506c67491feda to your computer and use it in GitHub Desktop.
Save olligobber/c97e9c97a7a5c0a4224506c67491feda to your computer and use it in GitHub Desktop.
Generates and exports infinitely many functions (uses all your ram at compile time) with template haskell
{-# LANGUAGE TemplateHaskell #-}
module Functions where
import FunctionsTemplate (generateFunctions)
generateFunctions
{-# LANGUAGE TemplateHaskell #-}
module FunctionsTemplate
( generateFunctions
) where
import qualified Language.Haskell.TH as TH
generateFunctions :: TH.Q [TH.Dec]
generateFunctions = mapM generateFunction [1..]
generateFunction :: Integer -> TH.Q TH.Dec
generateFunction n = declaration where
declaration = TH.funD name [TH.clause [] (TH.normalB [| id |]) []]
name = TH.mkName $ "a" <> show n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment