User Tools

Site Tools


codesnippets:templatehaskell

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
codesnippets:templatehaskell [2022/04/27 01:28] – created f2b216codesnippets:templatehaskell [2025/10/08 00:48] (current) – external edit 127.0.0.1
Line 20: Line 20:
     return $ LamE args (AppE (VarE f) ntup)     return $ LamE args (AppE (VarE f) ntup)
 </code> </code>
 +
 +===== Using the created code =====
 +
 +  * Example, uses the curry function by using the placeholder `$(C.curryN 3)` that will be expanded by ghc<code Haskell>
 +{-# LANGUAGE TemplateHaskell #-}
 +
 +module Lib
 +    (
 +        someFunc
 +    ) where
 +
 +import qualified Curry as C
 +
 +someFunc :: IO ()
 +someFunc = 
 +    do
 +        print $ $(C.curryN 3) f1 1 ' ' ["Hallo"]
 +        print $ $(C.curryN 3) f1 1 '_' ["Hallo","world"]
 +        print $ $(C.curryN 3) f1 1 '.' ["Hallo","world","!"]
 +
 +f1 :: (Int,Char,[String]) -> String
 +f1 (ni,ch,[]) = []
 +f1 (ni,ch,[s0]) = s0
 +f1 (ni,ch,s0:s1:rls) = s0 ++ replicate ni ch ++ f1 (ni,ch,s1:rls)
 +</code>
 +
 +
 +===== ✎ =====
 +~~DISCUSSION~~
codesnippets/templatehaskell.1651015723.txt.gz · Last modified: (external edit)

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki