Karya, built on 2018-05-31T02:46:59 (patch 0a1a35479c514820d77330ae8a978975ba22a47a)

Safe HaskellNone

Derive.Typecheck

Contents

Synopsis

signal functions

type wrappers

newtype DefaultReal Source #

Either RealTime or ScoreTime, but untyped defaults to RealTime. This has a short accessor to make unwrapping more concise.

Constructors

DefaultReal 

newtype DefaultScore Source #

Same as DefaultReal but untyped defaults to ScoreTime. This has a short accessor to make unwrapping more concise.

Constructors

DefaultScore 

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

Instances
Eq a => Eq (Positive a) # 
Instance details

Defined in Derive.Typecheck

Methods

(==) :: Positive a -> Positive a -> Bool #

(/=) :: Positive a -> Positive a -> Bool #

Fractional a => Fractional (Positive a) # 
Instance details

Defined in Derive.Typecheck

Num a => Num (Positive a) # 
Instance details

Defined in Derive.Typecheck

Show a => Show (Positive a) # 
Instance details

Defined in Derive.Typecheck

Methods

showsPrec :: Int -> Positive a -> ShowS #

show :: Positive a -> String #

showList :: [Positive a] -> ShowS #

ShowVal.ShowVal a => ShowVal.ShowVal (Positive a) # 
Instance details

Defined in Derive.Typecheck

Methods

show_val :: Positive a -> Text Source #

ToVal a => ToVal (Positive a) # 
Instance details

Defined in Derive.Typecheck

TypecheckNum a => Typecheck (Positive a) # 
Instance details

Defined in Derive.Typecheck

newtype NonNegative a Source #

Like Positive, but also includes 0.

Constructors

NonNegative 

Fields

Instances
Eq a => Eq (NonNegative a) # 
Instance details

Defined in Derive.Typecheck

Fractional a => Fractional (NonNegative a) # 
Instance details

Defined in Derive.Typecheck

Num a => Num (NonNegative a) # 
Instance details

Defined in Derive.Typecheck

Show a => Show (NonNegative a) # 
Instance details

Defined in Derive.Typecheck

ShowVal.ShowVal a => ShowVal.ShowVal (NonNegative a) # 
Instance details

Defined in Derive.Typecheck

ToVal a => ToVal (NonNegative a) # 
Instance details

Defined in Derive.Typecheck

TypecheckNum a => Typecheck (NonNegative a) # 
Instance details

Defined in Derive.Typecheck

newtype Normalized Source #

0 <= x <= 1

Constructors

Normalized 

Fields

Instances
Eq Normalized # 
Instance details

Defined in Derive.Typecheck

Show Normalized # 
Instance details

Defined in Derive.Typecheck

Pretty Normalized # 
Instance details

Defined in Derive.Typecheck

ShowVal.ShowVal Normalized # 
Instance details

Defined in Derive.Typecheck

ToVal Normalized # 
Instance details

Defined in Derive.Typecheck

Typecheck Normalized # 
Instance details

Defined in Derive.Typecheck

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 # 
Instance details

Defined in Derive.Typecheck

Methods

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

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

check :: (a -> Maybe b) -> Checked a -> Checked b Source #

Further check a Checked. I feel like this should correspond to some kind of monad transformer lift.

class Typecheck a where Source #

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

Instances
Typecheck Bool # 
Instance details

Defined in Derive.Typecheck

Typecheck Double # 
Instance details

Defined in Derive.Typecheck

Typecheck Int # 
Instance details

Defined in Derive.Typecheck

Typecheck Integer # 
Instance details

Defined in Derive.Typecheck

Typecheck Text # 
Instance details

Defined in Derive.Typecheck

Typecheck Highlight # 
Instance details

Defined in Derive.C.Prelude.Highlight

Typecheck ScoreTime.ScoreTime # 
Instance details

Defined in Derive.Typecheck

Typecheck RealTime.RealTime # 
Instance details

Defined in Derive.Typecheck

Typecheck Attrs.Attributes # 
Instance details

Defined in Derive.Typecheck

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.

Instance details

Defined in Derive.Typecheck

Typecheck Pitch.NoteNumber # 
Instance details

Defined in Derive.Typecheck

Typecheck Pitch.Pitch # 
Instance details

Defined in Derive.Typecheck

Typecheck Meter.RankName # 
Instance details

Defined in Derive.Typecheck

Typecheck Score.PControl # 
Instance details

Defined in Derive.Typecheck

Typecheck Score.Control # 
Instance details

Defined in Derive.Typecheck

Typecheck Score.Instrument # 
Instance details

Defined in Derive.Typecheck

Typecheck Expr.Str # 
Instance details

Defined in Derive.Typecheck

Typecheck Expr.Symbol # 
Instance details

Defined in Derive.Typecheck

Typecheck BaseTypes.ControlFunction # 
Instance details

Defined in Derive.Typecheck

Typecheck BaseTypes.PControlRef # 
Instance details

Defined in Derive.Typecheck

Typecheck BaseTypes.ControlRef #

Use a TypedFunction or Function instead of this.

Instance details

Defined in Derive.Typecheck

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.

Instance details

Defined in Derive.Typecheck

Typecheck BaseTypes.Val # 
Instance details

Defined in Derive.Typecheck

Typecheck BaseTypes.Duration # 
Instance details

Defined in Derive.Typecheck

Typecheck BaseTypes.Pitch # 
Instance details

Defined in Derive.Typecheck

Typecheck NotGiven # 
Instance details

Defined in Derive.Typecheck

Typecheck TransposeFunctionNn # 
Instance details

Defined in Derive.Typecheck

Typecheck TransposeFunctionChromatic # 
Instance details

Defined in Derive.Typecheck

Typecheck TransposeFunctionDiatonic # 
Instance details

Defined in Derive.Typecheck

Typecheck DefaultRealTimeFunction # 
Instance details

Defined in Derive.Typecheck

Typecheck DefaultDiatonic #

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

Instance details

Defined in Derive.Typecheck

Typecheck Normalized # 
Instance details

Defined in Derive.Typecheck

Typecheck DefaultScore # 
Instance details

Defined in Derive.Typecheck

Typecheck DefaultReal # 
Instance details

Defined in Derive.Typecheck

Typecheck Function # 
Instance details

Defined in Derive.Typecheck

Typecheck TypedFunction # 
Instance details

Defined in Derive.Typecheck

Typecheck FreeCodePosition # 
Instance details

Defined in Perform.Lilypond.Constants

Typecheck UpDown # 
Instance details

Defined in Derive.Call

Typecheck Speed # 
Instance details

Defined in Derive.Call.Speed

Typecheck Distribution # 
Instance details

Defined in Derive.C.Prelude.ControlFunction

Typecheck KotekanStyle # 
Instance details

Defined in Derive.C.Bali.Gangsa

Typecheck NorotStyle # 
Instance details

Defined in Derive.C.Bali.Gangsa

Typecheck Tuning # 
Instance details

Defined in Derive.Scale.BaliScales

Typecheck HarmonicType # 
Instance details

Defined in Derive.C.Prelude.Articulation

Typecheck Adjust # 
Instance details

Defined in Derive.C.Prelude.Trill

Typecheck Direction # 
Instance details

Defined in Derive.C.Prelude.Trill

Typecheck a => Typecheck [a] #

Non-lists are coerced into singleton lists.

Instance details

Defined in Derive.Typecheck

Typecheck a => Typecheck (Maybe a) #

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

Instance details

Defined in Derive.Typecheck

Typecheck (Ratio.Ratio Int) # 
Instance details

Defined in Derive.Typecheck

Typecheck a => Typecheck (NonEmpty a) # 
Instance details

Defined in Derive.Typecheck

Typecheck (Score.Typed Signal.Y) # 
Instance details

Defined in Derive.Typecheck

TypecheckNum a => Typecheck (NonNegative a) # 
Instance details

Defined in Derive.Typecheck

TypecheckNum a => Typecheck (Positive a) # 
Instance details

Defined in Derive.Typecheck

Typecheck (Position CodePosition) # 
Instance details

Defined in Derive.Call.Ly

(Typecheck a, Typecheck b) => Typecheck (Either a b) # 
Instance details

Defined in Derive.Typecheck

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 # 
Instance details

Defined in Derive.Typecheck

ToVal Double # 
Instance details

Defined in Derive.Typecheck

ToVal Int # 
Instance details

Defined in Derive.Typecheck

ToVal Integer # 
Instance details

Defined in Derive.Typecheck

ToVal Text # 
Instance details

Defined in Derive.Typecheck

ToVal ScoreTime.ScoreTime # 
Instance details

Defined in Derive.Typecheck

ToVal RealTime.RealTime # 
Instance details

Defined in Derive.Typecheck

ToVal Attrs.Attributes # 
Instance details

Defined in Derive.Typecheck

ToVal Pitch.Transpose # 
Instance details

Defined in Derive.Typecheck

ToVal Pitch.NoteNumber # 
Instance details

Defined in Derive.Typecheck

ToVal Pitch.Pitch # 
Instance details

Defined in Derive.Typecheck

ToVal Score.PControl # 
Instance details

Defined in Derive.Typecheck

ToVal Score.Control # 
Instance details

Defined in Derive.Typecheck

ToVal Score.Instrument # 
Instance details

Defined in Derive.Typecheck

ToVal Expr.Str # 
Instance details

Defined in Derive.Typecheck

ToVal Expr.Symbol # 
Instance details

Defined in Derive.Typecheck

ToVal BaseTypes.ControlFunction # 
Instance details

Defined in Derive.Typecheck

ToVal BaseTypes.PControlRef # 
Instance details

Defined in Derive.Typecheck

ToVal BaseTypes.ControlRef # 
Instance details

Defined in Derive.Typecheck

ToVal BaseTypes.Quoted # 
Instance details

Defined in Derive.Typecheck

ToVal BaseTypes.Val # 
Instance details

Defined in Derive.Typecheck

ToVal BaseTypes.Duration # 
Instance details

Defined in Derive.Typecheck

ToVal BaseTypes.Pitch # 
Instance details

Defined in Derive.Typecheck

ToVal NotGiven # 
Instance details

Defined in Derive.Typecheck

ToVal DefaultDiatonic # 
Instance details

Defined in Derive.Typecheck

ToVal Normalized # 
Instance details

Defined in Derive.Typecheck

ToVal DefaultScore # 
Instance details

Defined in Derive.Typecheck

ToVal DefaultReal # 
Instance details

Defined in Derive.Typecheck

ToVal FreeCodePosition # 
Instance details

Defined in Perform.Lilypond.Constants

ToVal Speed # 
Instance details

Defined in Derive.Call.Speed

ToVal a => ToVal [a] # 
Instance details

Defined in Derive.Typecheck

Methods

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

ToVal a => ToVal (Maybe a) # 
Instance details

Defined in Derive.Typecheck

ToVal (Ratio.Ratio Int) # 
Instance details

Defined in Derive.Typecheck

ToVal (Score.Typed Signal.Y) # 
Instance details

Defined in Derive.Typecheck

ToVal a => ToVal (NonNegative a) # 
Instance details

Defined in Derive.Typecheck

ToVal a => ToVal (Positive a) # 
Instance details

Defined in Derive.Typecheck

ToVal (Position CodePosition) # 
Instance details

Defined in Derive.Call.Ly

(ToVal a, ToVal b) => ToVal (Either a b) # 
Instance details

Defined in Derive.Typecheck

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.

Instances
TypecheckSymbol Bool # 
Instance details

Defined in Derive.Typecheck

TypecheckSymbol Highlight # 
Instance details

Defined in Derive.C.Prelude.Highlight

TypecheckSymbol Meter.RankName # 
Instance details

Defined in Derive.Typecheck

TypecheckSymbol FreeCodePosition # 
Instance details

Defined in Perform.Lilypond.Constants

TypecheckSymbol UpDown # 
Instance details

Defined in Derive.Call

TypecheckSymbol Distribution # 
Instance details

Defined in Derive.C.Prelude.ControlFunction

TypecheckSymbol KotekanStyle # 
Instance details

Defined in Derive.C.Bali.Gangsa

TypecheckSymbol NorotStyle # 
Instance details

Defined in Derive.C.Bali.Gangsa

TypecheckSymbol Tuning # 
Instance details

Defined in Derive.Scale.BaliScales

TypecheckSymbol HarmonicType # 
Instance details

Defined in Derive.C.Prelude.Articulation

TypecheckSymbol Adjust # 
Instance details

Defined in Derive.C.Prelude.Trill

TypecheckSymbol Direction # 
Instance details

Defined in Derive.C.Prelude.Trill

TypecheckSymbol (Position CodePosition) # 
Instance details

Defined in Derive.Call.Ly

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

Make a ShowVal from a Show instance.

class Typecheck a => TypecheckNum a where Source #

Minimal complete definition

num_type

Instances
TypecheckNum Double # 
Instance details

Defined in Derive.Typecheck

TypecheckNum Int # 
Instance details

Defined in Derive.Typecheck

TypecheckNum Integer # 
Instance details

Defined in Derive.Typecheck

TypecheckNum ScoreTime.ScoreTime # 
Instance details

Defined in Derive.Typecheck

TypecheckNum RealTime.RealTime # 
Instance details

Defined in Derive.Typecheck

TypecheckNum Pitch.Transpose # 
Instance details

Defined in Derive.Typecheck

TypecheckNum Pitch.NoteNumber # 
Instance details

Defined in Derive.Typecheck

TypecheckNum BaseTypes.Duration # 
Instance details

Defined in Derive.Typecheck

TypecheckNum DefaultDiatonic # 
Instance details

Defined in Derive.Typecheck

TypecheckNum DefaultScore # 
Instance details

Defined in Derive.Typecheck

TypecheckNum DefaultReal # 
Instance details

Defined in Derive.Typecheck

TypecheckNum Speed # 
Instance details

Defined in Derive.Call.Speed

TypecheckNum (Ratio.Ratio Int) # 
Instance details

Defined in Derive.Typecheck

TypecheckNum (Score.Typed Signal.Y) # 
Instance details

Defined in Derive.Typecheck

Typecheck instances

numeric types

num_to_scalar :: (Score.Typed Signal.Y -> Maybe a) -> BaseTypes.Val -> Checked a Source #

Coerce any numeric value to a Score.Typed Signal.Y, 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) -> (Score.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

data NotGiven Source #

Constructors

NotGiven 
Instances
Eq NotGiven # 
Instance details

Defined in Derive.Typecheck

Show NotGiven # 
Instance details

Defined in Derive.Typecheck

ShowVal.ShowVal NotGiven # 
Instance details

Defined in Derive.Typecheck

ToVal NotGiven # 
Instance details

Defined in Derive.Typecheck

Typecheck NotGiven # 
Instance details

Defined in Derive.Typecheck

util

data TimeType Source #

Constructors

Real 
Score 
Instances
Eq TimeType # 
Instance details

Defined in Derive.Typecheck

Show TimeType # 
Instance details

Defined in Derive.Typecheck

Pretty TimeType # 
Instance details

Defined in Derive.Typecheck

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

ShowVal.ShowVal Meter.RankName # 
Instance details

ShowVal.ShowVal Function # 
Instance details

ShowVal.ShowVal TypedFunction # 
Instance details