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

Safe HaskellNone

Derive.Typecheck

Contents

Synopsis

signal functions

type wrappers

real :: RealTime.RealTime -> DefaultReal Source #

Create DefaultReal and DefaultScores for use in Derive.Sig signatures for default values. It would be nice to use literals and let type inference do its thing, but there's no good definition for the rest of the methods in Integral and Fractional.

newtype Positive a Source #

An annotation that says this value must be >0. Instances only exist for numeric types.

This is an instance of Num just so numeric literals work. Of course that means you also have (-) which can make it not positive, but this is only intended to be a type tag for signatures, unwrapped as soon as it gets passed to the call.

Constructors

Positive 

Fields

newtype DefaultDiatonic Source #

Normally Transpose will default to Chromatic if the val is untyped, but some calls would prefer to default to Diatonic.

typecheck utils

typecheck :: forall a. Typecheck a => Text -> ScoreTime.ScoreTime -> BaseTypes.Val -> Derive.Deriver a Source #

Typecheck a single Val, and throw if it's the wrong type.

Typecheck class

data Checked a Source #

Constructors

Val (Maybe a) 
Eval (RealTime.RealTime -> Derive.Deriver (Maybe a))

This val needs to be evaluated to know if it will typecheck. The argument is the call start time, used when coercing a function to a scalar.

Instances

Functor Checked # 

Methods

fmap :: (a -> b) -> Checked a -> Checked b #

(<$) :: a -> Checked b -> Checked a #

class Typecheck a where Source #

This is the class of values which can be converted to from a BaseTypes.Val.

Instances

Typecheck Bool # 
Typecheck Double # 
Typecheck Int # 
Typecheck Text # 
Typecheck Pitch.Transpose #

VNums can also be coerced into chromatic transposition, so you can write a plain number if you don't care about diatonic.

This is different from BaseTypes.Duration, which does not default an untyped literal, so you have to supply the type explicitly. The rationale is that many scales don't have diatonic or chromatic, and it would be annoying to have to specify one or the other when it was definitely irrelevant. But the RealTime ScoreTime distinction is universal, there is no single default that is appropriate for all calls. So they have to specify a default by taking a DefaultScore or DefaultReal, or require the caller to distinguish with BaseTypes.Duration.

Typecheck Pitch.NoteNumber # 
Typecheck Pitch.Pitch # 
Typecheck ScoreTime.ScoreTime # 
Typecheck RealTime.RealTime # 
Typecheck TypedVal # 
Typecheck PControl # 
Typecheck Control # 
Typecheck Instrument # 
Typecheck Expr.Str # 
Typecheck Expr.Symbol # 
Typecheck Attrs.Attributes # 
Typecheck Meter.RankName # 
Typecheck BaseTypes.ControlFunction # 
Typecheck BaseTypes.PControlRef # 
Typecheck BaseTypes.ControlRef #

Use a TypedFunction or Function instead of this.

Typecheck BaseTypes.Quoted #

Anything except a pitch can be coerced to a quoted, using ShowVal. This means you can write a lot of things without quotes.

Pitches have to be quoted because they explicitly have an invalid ShowVal.

Typecheck BaseTypes.Val # 
Typecheck BaseTypes.Duration # 
Typecheck BaseTypes.Pitch # 
Typecheck NotGiven # 
Typecheck TransposeFunctionNn # 
Typecheck TransposeFunctionChromatic # 
Typecheck TransposeFunctionDiatonic # 
Typecheck DefaultRealTimeFunction # 
Typecheck DefaultDiatonic #

But some calls want to default to diatonic, not chromatic.

Typecheck Normalized # 
Typecheck DefaultScore # 
Typecheck DefaultReal # 
Typecheck Function # 
Typecheck TypedFunction # 
Typecheck UpDown # 
Typecheck Distribution # 
Typecheck Tuning # 
Typecheck Speed # 
Typecheck KotekanStyle # 
Typecheck NorotStyle # 
Typecheck Adjust # 
Typecheck Direction # 
(Typecheck a, ToVal a) => Typecheck [a] #

Non-lists are coerced into singleton lists.

Typecheck a => Typecheck (Maybe a) #

Putting Maybe in Typecheck means I can have optional arguments with no defaults. Further docs in defaulted.

TypecheckNum a => Typecheck (NonNegative a) # 
TypecheckNum a => Typecheck (Positive a) # 
(Typecheck a, Typecheck b) => Typecheck (Either a b) # 

eval :: Typecheck a => (a -> Derive.Deriver b) -> BaseTypes.Val -> Checked b Source #

Return a simple Eval check which doesn't depend on RealTime.

class ToVal a where Source #

Instances

ToVal Bool # 
ToVal Double # 
ToVal Int # 
ToVal Text # 
ToVal Pitch.Transpose # 
ToVal Pitch.NoteNumber # 
ToVal Pitch.Pitch # 
ToVal ScoreTime.ScoreTime # 
ToVal RealTime.RealTime # 
ToVal TypedVal # 
ToVal PControl # 
ToVal Control # 
ToVal Instrument # 
ToVal Expr.Str # 
ToVal Expr.Symbol # 
ToVal Attrs.Attributes # 
ToVal BaseTypes.ControlFunction # 
ToVal BaseTypes.PControlRef # 
ToVal BaseTypes.ControlRef # 
ToVal BaseTypes.Quoted # 
ToVal BaseTypes.Val # 
ToVal BaseTypes.Duration # 
ToVal BaseTypes.Pitch # 
ToVal NotGiven # 
ToVal DefaultDiatonic # 
ToVal Normalized # 
ToVal DefaultScore # 
ToVal DefaultReal # 
ToVal Speed # 
ToVal a => ToVal [a] # 

Methods

to_val :: [a] -> BaseTypes.Val Source #

ToVal a => ToVal (Maybe a) # 
ToVal a => ToVal (NonNegative a) # 
ToVal a => ToVal (Positive a) # 
(ToVal a, ToVal b) => ToVal (Either a b) # 

class ShowVal.ShowVal a => TypecheckSymbol a where Source #

This is for text strings which are parsed to call-specific types. You can declare an instance and the default Typecheck instance will allow you to incorporate the type directly into the signature of the call.

If your type is a Bounded Enum, you get a default parser, and the enum values go in the ValType.TStr so the docs can mention them.

So the type needs to be in (Bounded, Enum, ShowVal, TypecheckSymbol, Typecheck), though all of these can use default implementations.

enum_show_val :: Show a => a -> Text Source #

Make a ShowVal from a Show instance.

Typecheck instances

numeric types

num_to_scalar :: (TypedVal -> Maybe a) -> BaseTypes.Val -> Checked a Source #

Coerce any numeric value to a TypedVal, and check it against the given function.

num_to_function :: (TypedFunction -> Maybe a) -> BaseTypes.Val -> Checked a Source #

Coerce any numeric value to a function, and check it against the given function.

num_to_checked_function :: (Function -> typ -> b) -> (Type -> Maybe typ) -> BaseTypes.Val -> Checked b Source #

Like num_to_function, but take a constructor with a type argument, and a separate function to verify the type.

control_function :: BaseTypes.ControlFunction -> Derive.Deriver TypedFunction Source #

Evaluate a control function with no backing control.

eval only

scalar

text/symbol

other types

util

to_typed_function

to_typed_function :: BaseTypes.ControlRef -> Derive.Deriver TypedFunction Source #

Convert a BaseTypes.ControlRef to a function.

If a signal exists but doesn't have a type, the type will be inherited from the default. This way a call can cause a signal parameter to default to a certain type.

Orphan instances