mirror of
https://gitlab.com/sheaf/metabrush.git
synced 2024-11-05 23:03:38 +00:00
24 lines
597 B
Haskell
24 lines
597 B
Haskell
{-# LANGUAGE TemplateHaskell #-}
|
|
|
|
module TH.Utils where
|
|
|
|
-- template-haskell
|
|
import Language.Haskell.TH
|
|
( CodeQ )
|
|
|
|
-- brush-strokes
|
|
import Math.Ring ( Ring )
|
|
import qualified Math.Ring as Ring
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
foldQ :: CodeQ ( a -> a -> a ) -> CodeQ a -> [ CodeQ a ] -> CodeQ a
|
|
foldQ _ a0 [] = a0
|
|
foldQ _ _ [a] = a
|
|
foldQ f a0 (a:as) = [|| $$f $$a $$( foldQ f a0 as ) ||]
|
|
|
|
powQ :: Ring a => CodeQ a -> Word -> CodeQ a
|
|
powQ _ 0 = [|| Ring.fromInteger ( 1 :: Integer ) ||]
|
|
powQ x 1 = x
|
|
powQ x n = [|| $$x Ring.^ ( n :: Word ) ||]
|