{-# LANGUAGE DeriveFunctor #-}
module Derive.Expr where
import qualified Control.DeepSeq as DeepSeq
import qualified Data.List.NonEmpty as NonEmpty
import qualified Data.String as String
import qualified Data.Text as Text
import qualified Util.NEs as NEs
import qualified Util.Lists as Lists
import qualified Util.Serialize as Serialize
import qualified Derive.ScoreT as ScoreT
import Derive.ShowVal (ShowVal(show_val))
import qualified Perform.Pitch as Pitch
import qualified Perform.Signal as Signal
import Global
type Expr val = NonEmpty (Call val)
data Call val = Call Symbol [Term val]
deriving (Int -> Call val -> ShowS
forall val. Show val => Int -> Call val -> ShowS
forall val. Show val => [Call val] -> ShowS
forall val. Show val => Call val -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Call val] -> ShowS
$cshowList :: forall val. Show val => [Call val] -> ShowS
show :: Call val -> String
$cshow :: forall val. Show val => Call val -> String
showsPrec :: Int -> Call val -> ShowS
$cshowsPrec :: forall val. Show val => Int -> Call val -> ShowS
Show, ReadPrec [Call val]
ReadPrec (Call val)
ReadS [Call val]
forall val. Read val => ReadPrec [Call val]
forall val. Read val => ReadPrec (Call val)
forall val. Read val => Int -> ReadS (Call val)
forall val. Read val => ReadS [Call val]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Call val]
$creadListPrec :: forall val. Read val => ReadPrec [Call val]
readPrec :: ReadPrec (Call val)
$creadPrec :: forall val. Read val => ReadPrec (Call val)
readList :: ReadS [Call val]
$creadList :: forall val. Read val => ReadS [Call val]
readsPrec :: Int -> ReadS (Call val)
$creadsPrec :: forall val. Read val => Int -> ReadS (Call val)
Read, Call val -> Call val -> Bool
forall val. Eq val => Call val -> Call val -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Call val -> Call val -> Bool
$c/= :: forall val. Eq val => Call val -> Call val -> Bool
== :: Call val -> Call val -> Bool
$c== :: forall val. Eq val => Call val -> Call val -> Bool
Eq, forall a b. a -> Call b -> Call a
forall a b. (a -> b) -> Call a -> Call b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Call b -> Call a
$c<$ :: forall a b. a -> Call b -> Call a
fmap :: forall a b. (a -> b) -> Call a -> Call b
$cfmap :: forall a b. (a -> b) -> Call a -> Call b
Functor)
data Term val = ValCall (Call val) | Literal val
deriving (Int -> Term val -> ShowS
forall val. Show val => Int -> Term val -> ShowS
forall val. Show val => [Term val] -> ShowS
forall val. Show val => Term val -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Term val] -> ShowS
$cshowList :: forall val. Show val => [Term val] -> ShowS
show :: Term val -> String
$cshow :: forall val. Show val => Term val -> String
showsPrec :: Int -> Term val -> ShowS
$cshowsPrec :: forall val. Show val => Int -> Term val -> ShowS
Show, ReadPrec [Term val]
ReadPrec (Term val)
ReadS [Term val]
forall val. Read val => ReadPrec [Term val]
forall val. Read val => ReadPrec (Term val)
forall val. Read val => Int -> ReadS (Term val)
forall val. Read val => ReadS [Term val]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Term val]
$creadListPrec :: forall val. Read val => ReadPrec [Term val]
readPrec :: ReadPrec (Term val)
$creadPrec :: forall val. Read val => ReadPrec (Term val)
readList :: ReadS [Term val]
$creadList :: forall val. Read val => ReadS [Term val]
readsPrec :: Int -> ReadS (Term val)
$creadsPrec :: forall val. Read val => Int -> ReadS (Term val)
Read, Term val -> Term val -> Bool
forall val. Eq val => Term val -> Term val -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Term val -> Term val -> Bool
$c/= :: forall val. Eq val => Term val -> Term val -> Bool
== :: Term val -> Term val -> Bool
$c== :: forall val. Eq val => Term val -> Term val -> Bool
Eq, forall a b. a -> Term b -> Term a
forall a b. (a -> b) -> Term a -> Term b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Term b -> Term a
$c<$ :: forall a b. a -> Term b -> Term a
fmap :: forall a b. (a -> b) -> Term a -> Term b
$cfmap :: forall a b. (a -> b) -> Term a -> Term b
Functor)
instance String.IsString (Call val) where
fromString :: String -> Call val
fromString = forall val. Symbol -> Call val
call0 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IsString a => String -> a
String.fromString
instance String.IsString (Expr val) where
fromString :: String -> Expr val
fromString = forall val. Symbol -> Expr val
generator0 forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IsString a => String -> a
String.fromString
instance ShowVal (Expr Text) where show_val :: Expr Text -> Text
show_val = forall val. ShowVal (Call val) => Expr val -> Text
show_val_expr
instance ShowVal (Call Text) where show_val :: Call Text -> Text
show_val = forall val.
ShowVal (Term val) =>
(val -> Maybe Text) -> Call val -> Text
show_val_call (forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> a
id)
instance ShowVal (Term Text) where show_val :: Term Text -> Text
show_val = forall val. (ShowVal val, ShowVal (Call val)) => Term val -> Text
show_val_term
instance ShowVal (Expr MiniVal) where show_val :: Expr MiniVal -> Text
show_val = forall val. ShowVal (Call val) => Expr val -> Text
show_val_expr
instance ShowVal (Call MiniVal) where
show_val :: Call MiniVal -> Text
show_val = forall val.
ShowVal (Term val) =>
(val -> Maybe Text) -> Call val -> Text
show_val_call forall a b. (a -> b) -> a -> b
$ \case
VStr (Str Text
op) -> forall a. a -> Maybe a
Just Text
op
MiniVal
_ -> forall a. Maybe a
Nothing
instance ShowVal (Term MiniVal) where show_val :: Term MiniVal -> Text
show_val = forall val. (ShowVal val, ShowVal (Call val)) => Term val -> Text
show_val_term
instance Pretty (Call Text) where pretty :: Call Text -> Text
pretty = forall a. ShowVal a => a -> Text
show_val
instance Pretty (Term Text) where pretty :: Term Text -> Text
pretty = forall a. ShowVal a => a -> Text
show_val
instance Pretty (Call MiniVal) where pretty :: Call MiniVal -> Text
pretty = forall a. ShowVal a => a -> Text
show_val
instance Pretty (Term MiniVal) where pretty :: Term MiniVal -> Text
pretty = forall a. ShowVal a => a -> Text
show_val
show_val_expr :: ShowVal (Call val) => Expr val -> Text
show_val_expr :: forall val. ShowVal (Call val) => Expr val -> Text
show_val_expr = Text -> Text
Text.strip forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> [Text] -> Text
Text.intercalate Text
" | " forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall a. ShowVal a => a -> Text
show_val
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. NonEmpty a -> [a]
NonEmpty.toList
show_val_call :: ShowVal (Term val) => (val -> Maybe Text) -> Call val -> Text
show_val_call :: forall val.
ShowVal (Term val) =>
(val -> Maybe Text) -> Call val -> Text
show_val_call val -> Maybe Text
literal_str_of = \case
Call (Symbol Text
"=") [Term val
lhs, Term val
rhs] ->
[Text] -> Text
Text.unwords [forall a. ShowVal a => a -> Text
show_val Term val
lhs, Text
"=", forall a. ShowVal a => a -> Text
show_val Term val
rhs]
Call (Symbol Text
"=") [Term val
lhs, Term val
rhs, Literal val
op]
| Just Text
op <- val -> Maybe Text
literal_str_of val
op -> [Text] -> Text
Text.unwords
[ forall a. ShowVal a => a -> Text
show_val Term val
lhs
, Text
"=" forall a. Semigroup a => a -> a -> a
<> Text
op
, forall a. ShowVal a => a -> Text
show_val Term val
rhs
]
Call (Symbol Text
sym) [Term val]
terms -> [Text] -> Text
Text.unwords forall a b. (a -> b) -> a -> b
$ Text
sym forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map forall a. ShowVal a => a -> Text
show_val [Term val]
terms
show_val_term :: (ShowVal val, ShowVal (Call val)) => Term val -> Text
show_val_term :: forall val. (ShowVal val, ShowVal (Call val)) => Term val -> Text
show_val_term = \case
ValCall Call val
call -> Text
"(" forall a. Semigroup a => a -> a -> a
<> forall a. ShowVal a => a -> Text
show_val Call val
call forall a. Semigroup a => a -> a -> a
<> Text
")"
Literal val
val -> forall a. ShowVal a => a -> Text
show_val val
val
newtype Symbol = Symbol Text
deriving (Symbol -> Symbol -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Symbol -> Symbol -> Bool
$c/= :: Symbol -> Symbol -> Bool
== :: Symbol -> Symbol -> Bool
$c== :: Symbol -> Symbol -> Bool
Eq, Eq Symbol
Symbol -> Symbol -> Bool
Symbol -> Symbol -> Ordering
Symbol -> Symbol -> Symbol
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Symbol -> Symbol -> Symbol
$cmin :: Symbol -> Symbol -> Symbol
max :: Symbol -> Symbol -> Symbol
$cmax :: Symbol -> Symbol -> Symbol
>= :: Symbol -> Symbol -> Bool
$c>= :: Symbol -> Symbol -> Bool
> :: Symbol -> Symbol -> Bool
$c> :: Symbol -> Symbol -> Bool
<= :: Symbol -> Symbol -> Bool
$c<= :: Symbol -> Symbol -> Bool
< :: Symbol -> Symbol -> Bool
$c< :: Symbol -> Symbol -> Bool
compare :: Symbol -> Symbol -> Ordering
$ccompare :: Symbol -> Symbol -> Ordering
Ord, ReadPrec [Symbol]
ReadPrec Symbol
Int -> ReadS Symbol
ReadS [Symbol]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Symbol]
$creadListPrec :: ReadPrec [Symbol]
readPrec :: ReadPrec Symbol
$creadPrec :: ReadPrec Symbol
readList :: ReadS [Symbol]
$creadList :: ReadS [Symbol]
readsPrec :: Int -> ReadS Symbol
$creadsPrec :: Int -> ReadS Symbol
Read, Int -> Symbol -> ShowS
[Symbol] -> ShowS
Symbol -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Symbol] -> ShowS
$cshowList :: [Symbol] -> ShowS
show :: Symbol -> String
$cshow :: Symbol -> String
showsPrec :: Int -> Symbol -> ShowS
$cshowsPrec :: Int -> Symbol -> ShowS
Show, NonEmpty Symbol -> Symbol
Symbol -> Symbol -> Symbol
forall b. Integral b => b -> Symbol -> Symbol
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: forall b. Integral b => b -> Symbol -> Symbol
$cstimes :: forall b. Integral b => b -> Symbol -> Symbol
sconcat :: NonEmpty Symbol -> Symbol
$csconcat :: NonEmpty Symbol -> Symbol
<> :: Symbol -> Symbol -> Symbol
$c<> :: Symbol -> Symbol -> Symbol
Semigroup, Semigroup Symbol
Symbol
[Symbol] -> Symbol
Symbol -> Symbol -> Symbol
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [Symbol] -> Symbol
$cmconcat :: [Symbol] -> Symbol
mappend :: Symbol -> Symbol -> Symbol
$cmappend :: Symbol -> Symbol -> Symbol
mempty :: Symbol
$cmempty :: Symbol
Monoid, Symbol -> ()
forall a. (a -> ()) -> NFData a
rnf :: Symbol -> ()
$crnf :: Symbol -> ()
DeepSeq.NFData,
String -> Symbol
forall a. (String -> a) -> IsString a
fromString :: String -> Symbol
$cfromString :: String -> Symbol
String.IsString, [Symbol] -> Doc
Symbol -> Text
Symbol -> Doc
forall a. (a -> Text) -> (a -> Doc) -> ([a] -> Doc) -> Pretty a
formatList :: [Symbol] -> Doc
$cformatList :: [Symbol] -> Doc
format :: Symbol -> Doc
$cformat :: Symbol -> Doc
pretty :: Symbol -> Text
$cpretty :: Symbol -> Text
Pretty, Get Symbol
Putter Symbol
forall a. Putter a -> Get a -> Serialize a
get :: Get Symbol
$cget :: Get Symbol
put :: Putter Symbol
$cput :: Putter Symbol
Serialize.Serialize)
unsym :: Symbol -> Text
unsym :: Symbol -> Text
unsym (Symbol Text
sym) = Text
sym
instance ShowVal Symbol where
show_val :: Symbol -> Text
show_val (Symbol Text
sym) = Text
sym
expr :: [Call val] -> Call val -> Expr val
expr :: forall val. [Call val] -> Call val -> Expr val
expr [Call val]
trans Call val
gen = Call val
hd forall a. a -> [a] -> NonEmpty a
:| [Call val]
tl
where Call val
hd : [Call val]
tl = [Call val]
trans forall a. [a] -> [a] -> [a]
++ [Call val
gen]
generator :: Call val -> Expr val
generator :: forall val. Call val -> Expr val
generator = forall val. [Call val] -> Call val -> Expr val
expr []
generator0 :: Symbol -> Expr val
generator0 :: forall val. Symbol -> Expr val
generator0 = forall val. Call val -> Expr val
generator forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall val. Symbol -> Call val
call0
split :: Expr val -> ([Call val], Call val)
split :: forall val. Expr val -> ([Call val], Call val)
split = forall a. NonEmpty a -> ([a], a)
NEs.unsnoc
call :: Symbol -> [val] -> Call val
call :: forall val. Symbol -> [val] -> Call val
call Symbol
sym [val]
args = forall val. Symbol -> [Term val] -> Call val
Call Symbol
sym (forall a b. (a -> b) -> [a] -> [b]
map forall val. val -> Term val
Literal [val]
args)
call0 :: Symbol -> Call val
call0 :: forall val. Symbol -> Call val
call0 Symbol
sym = forall val. Symbol -> [Term val] -> Call val
Call Symbol
sym []
val_call :: Symbol -> [a] -> Term a
val_call :: forall a. Symbol -> [a] -> Term a
val_call Symbol
sym [a]
args = forall val. Call val -> Term val
ValCall (forall val. Symbol -> [val] -> Call val
call Symbol
sym [a]
args)
transform :: Call a -> Expr a -> Expr a
transform :: forall a. Call a -> Expr a -> Expr a
transform Call a
call (Call a
hd :| [Call a]
tl) = Call a
call forall a. a -> [a] -> NonEmpty a
:| (Call a
hd forall a. a -> [a] -> [a]
: [Call a]
tl)
transform0 :: Symbol -> Expr a -> Expr a
transform0 :: forall a. Symbol -> Expr a -> Expr a
transform0 = forall a. Call a -> Expr a -> Expr a
transform forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall val. Symbol -> Call val
call0
with :: ToExpr a => Symbol -> a -> Expr MiniVal
with :: forall a. ToExpr a => Symbol -> a -> Expr MiniVal
with Symbol
sym = forall a. Symbol -> Expr a -> Expr a
transform0 Symbol
sym forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. ToExpr a => a -> Expr MiniVal
to_expr
str_to_scale_id :: Str -> Pitch.ScaleId
str_to_scale_id :: Str -> ScaleId
str_to_scale_id = Text -> ScaleId
Pitch.ScaleId forall b c a. (b -> c) -> (a -> b) -> a -> c
. Str -> Text
unstr
scale_id_to_str :: Pitch.ScaleId -> Str
scale_id_to_str :: ScaleId -> Str
scale_id_to_str (Pitch.ScaleId Text
s) = Text -> Str
Str Text
s
map_symbol :: (Symbol -> Symbol) -> Call a -> Call a
map_symbol :: forall a. (Symbol -> Symbol) -> Call a -> Call a
map_symbol Symbol -> Symbol
f (Call Symbol
call [Term a]
args) = forall val. Symbol -> [Term val] -> Call val
Call (Symbol -> Symbol
f Symbol
call) [Term a]
args
map_literals :: (a -> b) -> Expr a -> Expr b
map_literals :: forall a b. (a -> b) -> Expr a -> Expr b
map_literals = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
map_generator :: (Symbol -> Symbol) -> Expr a -> Expr a
map_generator :: forall a. (Symbol -> Symbol) -> Expr a -> Expr a
map_generator Symbol -> Symbol
f (Call a
call1 :| [Call a]
calls) = case [Call a]
calls of
[] -> forall a. (Symbol -> Symbol) -> Call a -> Call a
map_symbol Symbol -> Symbol
f Call a
call1 forall a. a -> [a] -> NonEmpty a
:| []
Call a
_ : [Call a]
_ -> Call a
call1 forall a. a -> [a] -> NonEmpty a
:| forall a. (a -> a) -> [a] -> [a]
Lists.mapLast (forall a. (Symbol -> Symbol) -> Call a -> Call a
map_symbol Symbol -> Symbol
f) [Call a]
calls
class ToExpr a where
to_expr :: a -> Expr MiniVal
newtype Str = Str Text
deriving (Str -> Str -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Str -> Str -> Bool
$c/= :: Str -> Str -> Bool
== :: Str -> Str -> Bool
$c== :: Str -> Str -> Bool
Eq, Eq Str
Str -> Str -> Bool
Str -> Str -> Ordering
Str -> Str -> Str
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Str -> Str -> Str
$cmin :: Str -> Str -> Str
max :: Str -> Str -> Str
$cmax :: Str -> Str -> Str
>= :: Str -> Str -> Bool
$c>= :: Str -> Str -> Bool
> :: Str -> Str -> Bool
$c> :: Str -> Str -> Bool
<= :: Str -> Str -> Bool
$c<= :: Str -> Str -> Bool
< :: Str -> Str -> Bool
$c< :: Str -> Str -> Bool
compare :: Str -> Str -> Ordering
$ccompare :: Str -> Str -> Ordering
Ord, ReadPrec [Str]
ReadPrec Str
Int -> ReadS Str
ReadS [Str]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Str]
$creadListPrec :: ReadPrec [Str]
readPrec :: ReadPrec Str
$creadPrec :: ReadPrec Str
readList :: ReadS [Str]
$creadList :: ReadS [Str]
readsPrec :: Int -> ReadS Str
$creadsPrec :: Int -> ReadS Str
Read, Int -> Str -> ShowS
[Str] -> ShowS
Str -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Str] -> ShowS
$cshowList :: [Str] -> ShowS
show :: Str -> String
$cshow :: Str -> String
showsPrec :: Int -> Str -> ShowS
$cshowsPrec :: Int -> Str -> ShowS
Show, Str -> ()
forall a. (a -> ()) -> NFData a
rnf :: Str -> ()
$crnf :: Str -> ()
DeepSeq.NFData, String -> Str
forall a. (String -> a) -> IsString a
fromString :: String -> Str
$cfromString :: String -> Str
String.IsString,
Get Str
Putter Str
forall a. Putter a -> Get a -> Serialize a
get :: Get Str
$cget :: Get Str
put :: Putter Str
$cput :: Putter Str
Serialize.Serialize, Str -> Text
forall a. (a -> Text) -> ShowVal a
show_val :: Str -> Text
$cshow_val :: Str -> Text
ShowVal)
instance Pretty Str where pretty :: Str -> Text
pretty = forall a. ShowVal a => a -> Text
show_val
unstr :: Str -> Text
unstr :: Str -> Text
unstr (Str Text
str) = Text
str
data MiniVal = VNum !(ScoreT.Typed Signal.Y) | VStr !Str
deriving (MiniVal -> MiniVal -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MiniVal -> MiniVal -> Bool
$c/= :: MiniVal -> MiniVal -> Bool
== :: MiniVal -> MiniVal -> Bool
$c== :: MiniVal -> MiniVal -> Bool
Eq, Eq MiniVal
MiniVal -> MiniVal -> Bool
MiniVal -> MiniVal -> Ordering
MiniVal -> MiniVal -> MiniVal
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: MiniVal -> MiniVal -> MiniVal
$cmin :: MiniVal -> MiniVal -> MiniVal
max :: MiniVal -> MiniVal -> MiniVal
$cmax :: MiniVal -> MiniVal -> MiniVal
>= :: MiniVal -> MiniVal -> Bool
$c>= :: MiniVal -> MiniVal -> Bool
> :: MiniVal -> MiniVal -> Bool
$c> :: MiniVal -> MiniVal -> Bool
<= :: MiniVal -> MiniVal -> Bool
$c<= :: MiniVal -> MiniVal -> Bool
< :: MiniVal -> MiniVal -> Bool
$c< :: MiniVal -> MiniVal -> Bool
compare :: MiniVal -> MiniVal -> Ordering
$ccompare :: MiniVal -> MiniVal -> Ordering
Ord, Int -> MiniVal -> ShowS
[MiniVal] -> ShowS
MiniVal -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MiniVal] -> ShowS
$cshowList :: [MiniVal] -> ShowS
show :: MiniVal -> String
$cshow :: MiniVal -> String
showsPrec :: Int -> MiniVal -> ShowS
$cshowsPrec :: Int -> MiniVal -> ShowS
Show)
instance String.IsString MiniVal where
fromString :: String -> MiniVal
fromString = Str -> MiniVal
VStrforall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. IsString a => String -> a
String.fromString
instance ShowVal MiniVal where
show_val :: MiniVal -> Text
show_val (VNum Typed Y
v) = forall a. ShowVal a => a -> Text
show_val Typed Y
v
show_val (VStr Str
v) = forall a. ShowVal a => a -> Text
show_val Str
v
instance Pretty MiniVal where pretty :: MiniVal -> Text
pretty = forall a. ShowVal a => a -> Text
show_val
instance Serialize.Serialize MiniVal where
put :: Putter MiniVal
put (VNum Typed Y
a) = Word8 -> PutM ()
Serialize.put_tag Word8
0 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Serialize a => Putter a
Serialize.put Typed Y
a
put (VStr Str
a) = Word8 -> PutM ()
Serialize.put_tag Word8
1 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Serialize a => Putter a
Serialize.put Str
a
get :: Get MiniVal
get = Get Word8
Serialize.get_tag forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Word8
0 -> Typed Y -> MiniVal
VNum forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Serialize a => Get a
Serialize.get
Word8
1 -> Str -> MiniVal
VStr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Serialize a => Get a
Serialize.get
Word8
tag -> forall a. String -> Word8 -> Get a
Serialize.bad_tag String
"MiniVal" Word8
tag
class ToVal a where to_val :: a -> MiniVal
instance ToVal Int where to_val :: Int -> MiniVal
to_val Int
a = forall a. ToVal a => a -> MiniVal
to_val (forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
a :: Double)
instance ToVal Double where to_val :: Y -> MiniVal
to_val = Typed Y -> MiniVal
VNum forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Typed a
ScoreT.untyped
instance ToVal Text where to_val :: Text -> MiniVal
to_val = Str -> MiniVal
VStr forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Str
Str