Created
February 10, 2021 12:41
-
-
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
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 #-} | |
module Functions where | |
import FunctionsTemplate (generateFunctions) | |
generateFunctions |
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 #-} | |
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