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" forall a. [a] -> [a] -> [a]
++ 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" forall a. [a] -> [a] -> [a]
++ String
n 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 = forall a. Name a => a -> String
name a
x
m :: String
m = forall a. [a] -> a
head forall a b. (a -> b) -> a -> b
$ forall a. Name a => a -> [String]
names b
y 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 forall a. [a] -> [a] -> [a]
++ String
m
where
(a
x,b
y) = (a, b)
xy
n :: String
n = forall a. Name a => a -> String
name a
x
m :: String
m = forall a. [a] -> a
head forall a b. (a -> b) -> a -> b
$ forall a. Name a => a -> [String]
names b
y 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 forall a. [a] -> [a] -> [a]
++ String
m forall a. [a] -> [a] -> [a]
++ String
o
where
(a
x,b
y,c
z) = (a, b, c)
xyz
n :: String
n = forall a. Name a => a -> String
name a
x
m :: String
m = forall a. [a] -> a
head forall a b. (a -> b) -> a -> b
$ forall a. Name a => a -> [String]
names b
y forall a. Eq a => [a] -> [a] -> [a]
\\ [String
n]
o :: String
o = forall a. [a] -> a
head forall a b. (a -> b) -> a -> b
$ forall a. Name a => a -> [String]
names c
z 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 = forall a. Name a => a -> String
name a
x forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name b
y forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name c
z forall a. [a] -> [a] -> [a]
++ 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 = forall a. Name a => a -> String
name (forall a. [a] -> a
head [a]
xs) forall a. [a] -> [a] -> [a]
++ String
"s"
names :: Name a => a -> [String]
names :: forall a. Name a => a -> [String]
names = String -> [String]
variableNamesFromTemplate forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 = forall a. Name a => a -> String
name a
x forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name b
y forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name c
z forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name d
w forall a. [a] -> [a] -> [a]
++ 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 = forall a. Name a => a -> String
name a
x forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name b
y forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name c
z forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name d
w forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name e
v forall a. [a] -> [a] -> [a]
++ 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 = forall a. Name a => a -> String
name a
x forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name b
y forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name c
z forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name d
w
forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name e
v forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name f
u forall a. [a] -> [a] -> [a]
++ 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 = forall a. Name a => a -> String
name a
x forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name b
y forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name c
z forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name d
w
forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name e
v forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name f
u forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name g
t forall a. [a] -> [a] -> [a]
++ 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 = forall a. Name a => a -> String
name a
x forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name b
y forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name c
z forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name d
w
forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name e
v forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name f
u forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name g
t forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name h
s
forall a. [a] -> [a] -> [a]
++ 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 = forall a. Name a => a -> String
name a
x forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name b
y forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name c
z forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name d
w
forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name e
v forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name f
u forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name g
t forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name h
s
forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name i
r forall a. [a] -> [a] -> [a]
++ 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 = forall a. Name a => a -> String
name a
x forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name b
y forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name c
z forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name d
w
forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name e
v forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name f
u forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name g
t forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name h
s
forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name i
r forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name j
q forall a. [a] -> [a] -> [a]
++ 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 = forall a. Name a => a -> String
name a
x forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name b
y forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name c
z forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name d
w
forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name e
v forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name f
u forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name g
t forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name h
s
forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name i
r forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name j
q forall a. [a] -> [a] -> [a]
++ forall a. Name a => a -> String
name k
p forall a. [a] -> [a] -> [a]
++ 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