Karya, built on Mon Jul 24 11:39:07 PDT 2017 (patch 33511aca01257b76b88de7c7a2763b7a965c084e)

Safe HaskellNone

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

Documentation

data Type Source #

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 VQuoted. This has no Typecheck instance so it should never show up as a call argument.

TControlFunction 
TList !Type 
TOther !Text

Typecheck instances that don't correspond directly to a Val type get this, as a plain description.

Instances

Eq Type # 

Methods

(==) :: Type -> Type -> Bool #

(/=) :: Type -> Type -> Bool #

Ord Type # 

Methods

compare :: Type -> Type -> Ordering #

(<) :: Type -> Type -> Bool #

(<=) :: Type -> Type -> Bool #

(>) :: Type -> Type -> Bool #

(>=) :: Type -> Type -> Bool #

max :: Type -> Type -> Type #

min :: Type -> Type -> Type #

Show Type # 

Methods

showsPrec :: Int -> Type -> ShowS #

show :: Type -> String #

showList :: [Type] -> ShowS #

Pretty Type # 

data NumType Source #

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.

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.

infer_type_of Source #

Arguments

:: Bool

If True, infer the most specific type possible. Otherwise, infer a general type. This is because if put_val gets a 1 it doesn't mean it's intended to be a TPositive.

-> Val 
-> Type