{-# LANGUAGE TemplateHaskell, TypeOperators, DataKinds, PolyKinds,
ScopedTypeVariables, TypeFamilies, GADTs,
UndecidableInstances, BangPatterns #-}
module Data.Singletons.Prelude.Base (
Foldr, sFoldr, Map, sMap, type (++), (%++), Otherwise, sOtherwise,
Id, sId, Const, sConst, (:.), (%.), type ($), type ($!), (%$), (%$!),
Until, sUntil, Flip, sFlip, AsTypeOf, sAsTypeOf,
Seq, sSeq,
FoldrSym0, FoldrSym1, FoldrSym2, FoldrSym3,
MapSym0, MapSym1, MapSym2,
type (++@#@$), type (++@#@$$), type (++@#@$$$),
OtherwiseSym0,
IdSym0, IdSym1,
ConstSym0, ConstSym1, ConstSym2,
type (.@#@$), type (.@#@$$), type (.@#@$$$), type (.@#@$$$$),
type ($@#@$), type ($@#@$$), type ($@#@$$$),
type ($!@#@$), type ($!@#@$$), type ($!@#@$$$),
UntilSym0, UntilSym1, UntilSym2, UntilSym3,
FlipSym0, FlipSym1, FlipSym2, FlipSym3,
AsTypeOfSym0, AsTypeOfSym1, AsTypeOfSym2,
SeqSym0, SeqSym1, SeqSym2
) where
import Data.Singletons.Prelude.Instances
import Data.Singletons.Single
import Data.Singletons.Prelude.Bool
$(singletonsOnly [d|
foldr :: (a -> b -> b) -> b -> [a] -> b
foldr k z = go
where
go [] = z
go (y:ys) = y `k` go ys
map :: (a -> b) -> [a] -> [b]
map _ [] = []
map f (x:xs) = f x : map f xs
(++) :: [a] -> [a] -> [a]
(++) [] ys = ys
(++) (x:xs) ys = x : xs ++ ys
infixr 5 ++
id :: a -> a
id x = x
const :: a -> b -> a
const x _ = x
(.) :: (b -> c) -> (a -> b) -> a -> c
(.) f g = \x -> f (g x)
infixr 9 .
flip :: (a -> b -> c) -> b -> a -> c
flip f x y = f y x
asTypeOf :: a -> a -> a
asTypeOf = const
($) :: (a -> b) -> a -> b
f $ x = f x
infixr 0 $
($!) :: (a -> b) -> a -> b
f $! x = let vx = x in f vx
infixr 0 $!
until :: (a -> Bool) -> (a -> a) -> a -> a
until p f = go
where
go x = if p x then x else go (f x)
seq :: a -> b -> b
seq _ x = x
infixr 0 `seq`
|])
infixr 5 ++
infixr 0 $
infixr 0 $!