module Data.Express.Name
( Name (..)
, names
, variableNamesFromTemplate
)
where
import Data.Express.Utils.String
import Data.List
import Data.Int
import Data.Word
import Data.Ratio
import Data.Complex
import Data.Char
class Name a where
name :: a -> String
name a
_ = String
"x"
instance Name () where name :: () -> String
name ()
_ = String
"u"
instance Name Bool where name :: Bool -> String
name Bool
_ = String
"p"
instance Name Int where name :: Int -> String
name Int
_ = String
"x"
instance Name Integer where name :: Integer -> String
name Integer
_ = String
"x"
instance Name Char where name :: Char -> String
name Char
_ = String
"c"
instance Name Ordering where name :: Ordering -> String
name Ordering
_ = String
"o"
instance Name (Ratio a) where name :: Ratio a -> String
name Ratio a
_ = String
"q"
instance Name (Complex a) where name :: Complex a -> String
name Complex a
_ = String
"x"
instance Name Float where name :: Float -> String
name Float
_ = String
"x"
instance Name Double where name :: Double -> String
name Double
_ = String
"x"
instance Name (a -> b) where name :: (a -> b) -> String
name a -> b
_ = String
"f"
instance Name a => Name (Maybe a) where
name :: Maybe a -> String
name Maybe a
mx = String
"m" String -> String -> String
forall a. [a] -> [a] -> [a]
++ a -> String
forall a. Name a => a -> String
name a
x
where
Just a
x = Maybe a
mx
instance (Name a, Name b) => Name (Either a b) where
name :: Either a b -> String
name Either a b
exy = String
"e" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
n String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
m
where
Left a
x = Either a b
exy
Right b
y = Either a b
exy
n :: String
n = a -> String
forall a. Name a => a -> String
name a
x
m :: String
m = [String] -> String
forall a. [a] -> a
head ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ b -> [String]
forall a. Name a => a -> [String]
names b
y [String] -> [String] -> [String]
forall a. Eq a => [a] -> [a] -> [a]
\\ [String
n]
instance (Name a, Name b) => Name (a,b) where
name :: (a, b) -> String
name (a, b)
xy = String
n String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
m
where
(a
x,b
y) = (a, b)
xy
n :: String
n = a -> String
forall a. Name a => a -> String
name a
x
m :: String
m = [String] -> String
forall a. [a] -> a
head ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ b -> [String]
forall a. Name a => a -> [String]
names b
y [String] -> [String] -> [String]
forall a. Eq a => [a] -> [a] -> [a]
\\ [String
n]
instance (Name a, Name b, Name c) => Name (a,b,c) where
name :: (a, b, c) -> String
name (a, b, c)
xyz = String
n String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
m String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
o
where
(a
x,b
y,c
z) = (a, b, c)
xyz
n :: String
n = a -> String
forall a. Name a => a -> String
name a
x
m :: String
m = [String] -> String
forall a. [a] -> a
head ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ b -> [String]
forall a. Name a => a -> [String]
names b
y [String] -> [String] -> [String]
forall a. Eq a => [a] -> [a] -> [a]
\\ [String
n]
o :: String
o = [String] -> String
forall a. [a] -> a
head ([String] -> String) -> [String] -> String
forall a b. (a -> b) -> a -> b
$ c -> [String]
forall a. Name a => a -> [String]
names c
z [String] -> [String] -> [String]
forall a. Eq a => [a] -> [a] -> [a]
\\ [String
n,String
m]
instance (Name a, Name b, Name c, Name d) => Name (a,b,c,d) where
name :: (a, b, c, d) -> String
name (a, b, c, d)
xyzw = a -> String
forall a. Name a => a -> String
name a
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ b -> String
forall a. Name a => a -> String
name b
y String -> String -> String
forall a. [a] -> [a] -> [a]
++ c -> String
forall a. Name a => a -> String
name c
z String -> String -> String
forall a. [a] -> [a] -> [a]
++ d -> String
forall a. Name a => a -> String
name d
w where (a
x,b
y,c
z,d
w) = (a, b, c, d)
xyzw
instance Name a => Name [a] where
name :: [a] -> String
name [a]
xs = a -> String
forall a. Name a => a -> String
name ([a] -> a
forall a. [a] -> a
head [a]
xs) String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
"s"
names :: Name a => a -> [String]
names :: a -> [String]
names = String -> [String]
variableNamesFromTemplate (String -> [String]) -> (a -> String) -> a -> [String]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> String
forall a. Name a => a -> String
name
instance Name Word where name :: Word -> String
name Word
_ = String
"x"
instance Name Int8 where name :: Int8 -> String
name Int8
_ = String
"x"
instance Name Int16 where name :: Int16 -> String
name Int16
_ = String
"x"
instance Name Int32 where name :: Int32 -> String
name Int32
_ = String
"x"
instance Name Int64 where name :: Int64 -> String
name Int64
_ = String
"x"
instance Name Word8 where name :: Word8 -> String
name Word8
_ = String
"x"
instance Name Word16 where name :: Word16 -> String
name Word16
_ = String
"x"
instance Name Word32 where name :: Word32 -> String
name Word32
_ = String
"x"
instance Name Word64 where name :: Word64 -> String
name Word64
_ = String
"x"
instance Name GeneralCategory where name :: GeneralCategory -> String
name GeneralCategory
_ = String
"c"
instance (Name a, Name b, Name c, Name d, Name e) => Name (a,b,c,d,e) where
name :: (a, b, c, d, e) -> String
name (a, b, c, d, e)
xyzwv = a -> String
forall a. Name a => a -> String
name a
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ b -> String
forall a. Name a => a -> String
name b
y String -> String -> String
forall a. [a] -> [a] -> [a]
++ c -> String
forall a. Name a => a -> String
name c
z String -> String -> String
forall a. [a] -> [a] -> [a]
++ d -> String
forall a. Name a => a -> String
name d
w String -> String -> String
forall a. [a] -> [a] -> [a]
++ e -> String
forall a. Name a => a -> String
name e
v
where (a
x,b
y,c
z,d
w,e
v) = (a, b, c, d, e)
xyzwv
instance (Name a, Name b, Name c, Name d, Name e, Name f)
=> Name (a,b,c,d,e,f) where
name :: (a, b, c, d, e, f) -> String
name (a, b, c, d, e, f)
xyzwvu = a -> String
forall a. Name a => a -> String
name a
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ b -> String
forall a. Name a => a -> String
name b
y String -> String -> String
forall a. [a] -> [a] -> [a]
++ c -> String
forall a. Name a => a -> String
name c
z String -> String -> String
forall a. [a] -> [a] -> [a]
++ d -> String
forall a. Name a => a -> String
name d
w String -> String -> String
forall a. [a] -> [a] -> [a]
++ e -> String
forall a. Name a => a -> String
name e
v String -> String -> String
forall a. [a] -> [a] -> [a]
++ f -> String
forall a. Name a => a -> String
name f
u
where (a
x,b
y,c
z,d
w,e
v,f
u) = (a, b, c, d, e, f)
xyzwvu
instance (Name a, Name b, Name c, Name d, Name e, Name f, Name g)
=> Name (a,b,c,d,e,f,g) where
name :: (a, b, c, d, e, f, g) -> String
name (a, b, c, d, e, f, g)
xyzwvut = a -> String
forall a. Name a => a -> String
name a
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ b -> String
forall a. Name a => a -> String
name b
y String -> String -> String
forall a. [a] -> [a] -> [a]
++ c -> String
forall a. Name a => a -> String
name c
z String -> String -> String
forall a. [a] -> [a] -> [a]
++ d -> String
forall a. Name a => a -> String
name d
w
String -> String -> String
forall a. [a] -> [a] -> [a]
++ e -> String
forall a. Name a => a -> String
name e
v String -> String -> String
forall a. [a] -> [a] -> [a]
++ f -> String
forall a. Name a => a -> String
name f
u String -> String -> String
forall a. [a] -> [a] -> [a]
++ g -> String
forall a. Name a => a -> String
name g
t
where (a
x,b
y,c
z,d
w,e
v,f
u,g
t) = (a, b, c, d, e, f, g)
xyzwvut
instance (Name a, Name b, Name c, Name d, Name e, Name f, Name g, Name h)
=> Name (a,b,c,d,e,f,g,h) where
name :: (a, b, c, d, e, f, g, h) -> String
name (a, b, c, d, e, f, g, h)
xyzwvuts = a -> String
forall a. Name a => a -> String
name a
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ b -> String
forall a. Name a => a -> String
name b
y String -> String -> String
forall a. [a] -> [a] -> [a]
++ c -> String
forall a. Name a => a -> String
name c
z String -> String -> String
forall a. [a] -> [a] -> [a]
++ d -> String
forall a. Name a => a -> String
name d
w
String -> String -> String
forall a. [a] -> [a] -> [a]
++ e -> String
forall a. Name a => a -> String
name e
v String -> String -> String
forall a. [a] -> [a] -> [a]
++ f -> String
forall a. Name a => a -> String
name f
u String -> String -> String
forall a. [a] -> [a] -> [a]
++ g -> String
forall a. Name a => a -> String
name g
t String -> String -> String
forall a. [a] -> [a] -> [a]
++ h -> String
forall a. Name a => a -> String
name h
s
where (a
x,b
y,c
z,d
w,e
v,f
u,g
t,h
s) = (a, b, c, d, e, f, g, h)
xyzwvuts
instance ( Name a, Name b, Name c, Name d
, Name e, Name f, Name g, Name h
, Name i)
=> Name (a,b,c,d,e,f,g,h,i) where
name :: (a, b, c, d, e, f, g, h, i) -> String
name (a, b, c, d, e, f, g, h, i)
xyzwvutsr = a -> String
forall a. Name a => a -> String
name a
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ b -> String
forall a. Name a => a -> String
name b
y String -> String -> String
forall a. [a] -> [a] -> [a]
++ c -> String
forall a. Name a => a -> String
name c
z String -> String -> String
forall a. [a] -> [a] -> [a]
++ d -> String
forall a. Name a => a -> String
name d
w
String -> String -> String
forall a. [a] -> [a] -> [a]
++ e -> String
forall a. Name a => a -> String
name e
v String -> String -> String
forall a. [a] -> [a] -> [a]
++ f -> String
forall a. Name a => a -> String
name f
u String -> String -> String
forall a. [a] -> [a] -> [a]
++ g -> String
forall a. Name a => a -> String
name g
t String -> String -> String
forall a. [a] -> [a] -> [a]
++ h -> String
forall a. Name a => a -> String
name h
s
String -> String -> String
forall a. [a] -> [a] -> [a]
++ i -> String
forall a. Name a => a -> String
name i
r
where (a
x,b
y,c
z,d
w,e
v,f
u,g
t,h
s,i
r) = (a, b, c, d, e, f, g, h, i)
xyzwvutsr
instance ( Name a, Name b, Name c, Name d
, Name e, Name f, Name g, Name h
, Name i, Name j )
=> Name (a,b,c,d,e,f,g,h,i,j) where
name :: (a, b, c, d, e, f, g, h, i, j) -> String
name (a, b, c, d, e, f, g, h, i, j)
xyzwvutsrq = a -> String
forall a. Name a => a -> String
name a
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ b -> String
forall a. Name a => a -> String
name b
y String -> String -> String
forall a. [a] -> [a] -> [a]
++ c -> String
forall a. Name a => a -> String
name c
z String -> String -> String
forall a. [a] -> [a] -> [a]
++ d -> String
forall a. Name a => a -> String
name d
w
String -> String -> String
forall a. [a] -> [a] -> [a]
++ e -> String
forall a. Name a => a -> String
name e
v String -> String -> String
forall a. [a] -> [a] -> [a]
++ f -> String
forall a. Name a => a -> String
name f
u String -> String -> String
forall a. [a] -> [a] -> [a]
++ g -> String
forall a. Name a => a -> String
name g
t String -> String -> String
forall a. [a] -> [a] -> [a]
++ h -> String
forall a. Name a => a -> String
name h
s
String -> String -> String
forall a. [a] -> [a] -> [a]
++ i -> String
forall a. Name a => a -> String
name i
r String -> String -> String
forall a. [a] -> [a] -> [a]
++ j -> String
forall a. Name a => a -> String
name j
q
where (a
x,b
y,c
z,d
w,e
v,f
u,g
t,h
s,i
r,j
q) = (a, b, c, d, e, f, g, h, i, j)
xyzwvutsrq
instance ( Name a, Name b, Name c, Name d
, Name e, Name f, Name g, Name h
, Name i, Name j, Name k )
=> Name (a,b,c,d,e,f,g,h,i,j,k) where
name :: (a, b, c, d, e, f, g, h, i, j, k) -> String
name (a, b, c, d, e, f, g, h, i, j, k)
xyzwvutsrqp = a -> String
forall a. Name a => a -> String
name a
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ b -> String
forall a. Name a => a -> String
name b
y String -> String -> String
forall a. [a] -> [a] -> [a]
++ c -> String
forall a. Name a => a -> String
name c
z String -> String -> String
forall a. [a] -> [a] -> [a]
++ d -> String
forall a. Name a => a -> String
name d
w
String -> String -> String
forall a. [a] -> [a] -> [a]
++ e -> String
forall a. Name a => a -> String
name e
v String -> String -> String
forall a. [a] -> [a] -> [a]
++ f -> String
forall a. Name a => a -> String
name f
u String -> String -> String
forall a. [a] -> [a] -> [a]
++ g -> String
forall a. Name a => a -> String
name g
t String -> String -> String
forall a. [a] -> [a] -> [a]
++ h -> String
forall a. Name a => a -> String
name h
s
String -> String -> String
forall a. [a] -> [a] -> [a]
++ i -> String
forall a. Name a => a -> String
name i
r String -> String -> String
forall a. [a] -> [a] -> [a]
++ j -> String
forall a. Name a => a -> String
name j
q String -> String -> String
forall a. [a] -> [a] -> [a]
++ k -> String
forall a. Name a => a -> String
name k
p
where (a
x,b
y,c
z,d
w,e
v,f
u,g
t,h
s,i
r,j
q,k
p) = (a, b, c, d, e, f, g, h, i, j, k)
xyzwvutsrqp
instance ( Name a, Name b, Name c, Name d
, Name e, Name f, Name g, Name h
, Name i, Name j, Name k, Name l )
=> Name (a,b,c,d,e,f,g,h,i,j,k,l) where
name :: (a, b, c, d, e, f, g, h, i, j, k, l) -> String
name (a, b, c, d, e, f, g, h, i, j, k, l)
xyzwvutsrqpo = a -> String
forall a. Name a => a -> String
name a
x String -> String -> String
forall a. [a] -> [a] -> [a]
++ b -> String
forall a. Name a => a -> String
name b
y String -> String -> String
forall a. [a] -> [a] -> [a]
++ c -> String
forall a. Name a => a -> String
name c
z String -> String -> String
forall a. [a] -> [a] -> [a]
++ d -> String
forall a. Name a => a -> String
name d
w
String -> String -> String
forall a. [a] -> [a] -> [a]
++ e -> String
forall a. Name a => a -> String
name e
v String -> String -> String
forall a. [a] -> [a] -> [a]
++ f -> String
forall a. Name a => a -> String
name f
u String -> String -> String
forall a. [a] -> [a] -> [a]
++ g -> String
forall a. Name a => a -> String
name g
t String -> String -> String
forall a. [a] -> [a] -> [a]
++ h -> String
forall a. Name a => a -> String
name h
s
String -> String -> String
forall a. [a] -> [a] -> [a]
++ i -> String
forall a. Name a => a -> String
name i
r String -> String -> String
forall a. [a] -> [a] -> [a]
++ j -> String
forall a. Name a => a -> String
name j
q String -> String -> String
forall a. [a] -> [a] -> [a]
++ k -> String
forall a. Name a => a -> String
name k
p String -> String -> String
forall a. [a] -> [a] -> [a]
++ l -> String
forall a. Name a => a -> String
name l
o
where (a
x,b
y,c
z,d
w,e
v,f
u,g
t,h
s,i
r,j
q,k
p,l
o) = (a, b, c, d, e, f, g, h, i, j, k, l)
xyzwvutsrqpo