Safe Haskell | Safe-Inferred |
---|
Derive.ValType
Description
Type descriptions of the Val
.
This is in its own module so Derive.Deriver.Monad can import it without importing Derive.Typecheck.
Synopsis
- data Type
- data NumType
- data NumValue
- types_match :: Type -> Type -> Bool
- val_types_match :: Val -> Val -> Maybe Type
- subtypes_of :: NumType -> [NumType]
- append_parens :: Text -> Text -> Text
- type_of :: Val -> Type
- infer_type_of :: Bool -> Val -> Type
- to_num_type :: ScoreT.Type -> NumType
Documentation
Constructors
TNum NumType NumValue | |
TAttributes | |
TControlRef | |
TPControlRef | |
TPitch | |
TNotePitch | |
TStr (Maybe [Text]) | Text string, with enum values if it's an enum. |
TControl | |
TPControl | |
TNotGiven | |
TSeparator | |
TMaybe Type | |
TEither Type Type | |
TVal | This is the "any" type. |
TPair Type Type | Two types in sequence. This has no corresponding Typecheck instance since it doesn't correspond to a single Val, but is used by Derive.Sig for documentation. |
TQuoted | A |
TControlFunction | |
TList !Type | |
TDeriver !Text | |
TOther !Text | Typecheck instances that don't correspond directly to a Val type get this, as a plain description. |
These are kind of muddled. This is because they were originally just
documentation, so the more specific the better, but are also used for
typechecking in put_val
, so the subtype relations need to be
respected. But since some are just documentation (e.g. TDefaultReal), they
should never show up on the LHS of a put_val typecheck.
Constructors
TUntyped | |
TInt | |
TTranspose | |
TDefaultDiatonic | |
TDefaultChromatic | |
TNoteNumber | |
TTime | |
TDefaultReal | |
TDefaultScore | |
TRealTime | |
TScoreTime |
Numeric subtypes.
Constructors
TAny | |
TNonNegative | =0 |
TPositive | 0 |
TNormalized | 0 <= a <= 1 |
TNormalizedBipolar |
|
types_match :: Type -> Type -> Bool Source #
This typechecking already exists in the Typecheck instances, but all it
can do is go from a Val to a Typecheck a => Maybe a
. So I can't reuse it
to check a type against a type, so it has to be duplicated, similar to how
type_of
can't reuse to_type
.
The result is I have redundant functions like subtypes_of
and type_of
and to_num_type
, and a mistake or inconsistency with to_type
or to_val
will cause typechecking to fail in some subtle case. Fortunately there are
relatively few types and hopefully won't be many more, and it only affects
put_val
. It could all do with a cleanup. I'm sure there's a
right way to do this sort of thing.
val_types_match :: Val -> Val -> Maybe Type Source #
Nothing if the type of the rhs matches the lhs, otherwise the expected type.
subtypes_of :: NumType -> [NumType] Source #
to_num_type :: ScoreT.Type -> NumType Source #