Karya, built on 2023-08-29T07:47:28 (patch 7a412d5d6ba4968ca4155ef276a062ccdeb9109a)
Safe HaskellSafe-Inferred

Derive.Typecheck

Synopsis

signal functions

data RealTimeFunctionT Source #

Returning them separately is used in (at least) Speed.starts

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

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

Defined in Derive.Typecheck

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

Defined in Derive.Typecheck

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

Defined in Derive.Typecheck

Methods

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

show :: Positive a -> String #

showList :: [Positive a] -> ShowS #

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

Defined in Derive.Typecheck

Methods

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

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

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

Defined in Derive.Typecheck

Methods

show_val :: Positive a -> Text Source #

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

Defined in Derive.Typecheck

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

Defined in Derive.Typecheck

newtype NonNegative a Source #

Like Positive, but also includes 0.

Constructors

NonNegative 

Fields

Instances

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

Defined in Derive.Typecheck

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

Defined in Derive.Typecheck

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

Defined in Derive.Typecheck

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

Defined in Derive.Typecheck

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

Defined in Derive.Typecheck

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

Defined in Derive.Typecheck

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

Defined in Derive.Typecheck

newtype Normalized Source #

0 <= x <= 1

Constructors

Normalized 

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

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

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

typecheck_simple :: forall a. Typecheck a => DeriveT.Val -> Either Text a Source #

Typecheck a simple value, with no evaluation. This means you can't get a deriver or coerce signal to a number.

data Checked a Source #

Constructors

Val (Result 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. This is needed when coercing a function to a scalar, because I only know the value to check after calling the function.

Instances

Instances details
Functor Checked Source # 
Instance details

Defined in Derive.Typecheck

Methods

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

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

data Result a Source #

Constructors

Failure 
Success !a 
Derive !(Derive.Context Derive.Tagged -> a)

This is a {Note,Control,Pitch}Deriver, which needs a Context to evaluate. DeriveT.Quoted can be coerced to this, at which point eval_quoted needs a Context. As with Quoted evaluation in general, this is only supported by Derive.Sig, not by the general typecehck mechanism.

Instances

Instances details
Functor Result Source # 
Instance details

Defined in Derive.Typecheck

Methods

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

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

class Typecheck a where Source #

This is the class of values which can be converted to a Checked. ToVal is the inverse transformation.

Minimal complete definition

Nothing

Instances

Instances details
Typecheck Attrs.Attributes Source # 
Instance details

Defined in Derive.Typecheck

Typecheck KotekanStyle Source # 
Instance details

Defined in Derive.C.Bali.Gangsa

Typecheck NorotStyle Source # 
Instance details

Defined in Derive.C.Bali.Gangsa

Typecheck HarmonicType Source # 
Instance details

Defined in Derive.C.Prelude.Articulation

Typecheck Adjust Source # 
Instance details

Defined in Derive.C.Prelude.Trill

Typecheck Direction Source # 
Instance details

Defined in Derive.C.Prelude.Trill

Typecheck Hand Source # 
Instance details

Defined in Derive.Call

Typecheck UpDown Source # 
Instance details

Defined in Derive.Call

Typecheck Speed Source # 
Instance details

Defined in Derive.Call.Speed

Typecheck SubT.Track Source # 
Instance details

Defined in Derive.Typecheck

Typecheck DeriveT.CFunction Source # 
Instance details

Defined in Derive.Typecheck

Typecheck DeriveT.Duration Source # 
Instance details

Defined in Derive.Typecheck

Typecheck DeriveT.PFunction Source # 
Instance details

Defined in Derive.Typecheck

Typecheck DeriveT.PSignal Source # 
Instance details

Defined in Derive.Typecheck

Typecheck DeriveT.Pitch Source # 
Instance details

Defined in Derive.Typecheck

Typecheck DeriveT.PitchFunction Source # 
Instance details

Defined in Derive.Typecheck

Typecheck DeriveT.Quoted Source #

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 DeriveT.Val Source # 
Instance details

Defined in Derive.Typecheck

Typecheck Derive.ControlDeriver Source # 
Instance details

Defined in Derive.Sig

Typecheck Derive.NoteDeriver Source # 
Instance details

Defined in Derive.Sig

Typecheck Derive.PitchDeriver Source # 
Instance details

Defined in Derive.Sig

Typecheck Expr.Str Source # 
Instance details

Defined in Derive.Typecheck

Typecheck Expr.Symbol Source # 
Instance details

Defined in Derive.Typecheck

Typecheck Tuning Source # 
Instance details

Defined in Derive.Scale.BaliScales

Typecheck ScoreT.Control Source # 
Instance details

Defined in Derive.Typecheck

Typecheck ScoreT.Function Source # 
Instance details

Defined in Derive.Typecheck

Typecheck ScoreT.Instrument Source # 
Instance details

Defined in Derive.Typecheck

Typecheck ScoreT.PControl Source # 
Instance details

Defined in Derive.Typecheck

Typecheck ScoreT.Type Source # 
Instance details

Defined in Derive.Typecheck

Typecheck ScoreT.TypedFunction Source # 
Instance details

Defined in Derive.Typecheck

Typecheck ScoreT.TypedSignal Source # 
Instance details

Defined in Derive.Typecheck

Typecheck ChromaticTransposeFunctionT Source # 
Instance details

Defined in Derive.Typecheck

Typecheck DefaultDiatonic Source #

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

Instance details

Defined in Derive.Typecheck

Typecheck DefaultReal Source # 
Instance details

Defined in Derive.Typecheck

Typecheck DefaultScore Source # 
Instance details

Defined in Derive.Typecheck

Typecheck DiatonicTransposeFunctionT Source # 
Instance details

Defined in Derive.Typecheck

Typecheck NnTransposeFunctionT Source # 
Instance details

Defined in Derive.Typecheck

Typecheck Normalized Source # 
Instance details

Defined in Derive.Typecheck

Typecheck NormalizedBipolar Source # 
Instance details

Defined in Derive.Typecheck

Typecheck RealTimeFunction Source # 
Instance details

Defined in Derive.Typecheck

Typecheck RealTimeFunctionT Source # 
Instance details

Defined in Derive.Typecheck

Typecheck ScoreTimeFunction Source # 
Instance details

Defined in Derive.Typecheck

Typecheck ScoreTimeFunctionT Source # 
Instance details

Defined in Derive.Typecheck

Typecheck FreeCodePosition Source # 
Instance details

Defined in Perform.Lilypond.Constants

Typecheck Pitch.NoteNumber Source # 
Instance details

Defined in Derive.Typecheck

Typecheck Pitch.Pitch Source # 
Instance details

Defined in Derive.Typecheck

Typecheck Pitch.Transpose Source #

VSignals 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 DeriveT.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 DeriveT.Duration.

Instance details

Defined in Derive.Typecheck

Typecheck RealTime.RealTime Source # 
Instance details

Defined in Derive.Typecheck

Typecheck Signal.Control Source # 
Instance details

Defined in Derive.Typecheck

Typecheck Highlight Source # 
Instance details

Defined in Derive.C.Prelude.Highlight

Typecheck Meter.Rank Source # 
Instance details

Defined in Derive.Typecheck

Typecheck ScoreTime.ScoreTime Source # 
Instance details

Defined in Derive.Typecheck

Typecheck Text Source # 
Instance details

Defined in Derive.Typecheck

Typecheck Integer Source # 
Instance details

Defined in Derive.Typecheck

Typecheck Bool Source # 
Instance details

Defined in Derive.Typecheck

Typecheck Double Source # 
Instance details

Defined in Derive.Typecheck

Typecheck Int Source # 
Instance details

Defined in Derive.Typecheck

Typecheck (Ratio.Ratio Int) Source # 
Instance details

Defined in Derive.Typecheck

(Typecheck a, Ord a) => Typecheck (Set a) Source # 
Instance details

Defined in Derive.Typecheck

Typecheck (Position CodePosition) Source # 
Instance details

Defined in Derive.Call.Ly

Typecheck (ScoreT.Typed Signal.Y) Source # 
Instance details

Defined in Derive.Typecheck

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

Defined in Derive.Typecheck

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

Defined in Derive.Typecheck

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

Defined in Derive.Typecheck

Typecheck a => Typecheck (Maybe a) Source #

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

Instance details

Defined in Derive.Typecheck

Typecheck a => Typecheck [a] Source #

A non-list is coerced into a singleton list.

Instance details

Defined in Derive.Typecheck

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

Defined in Derive.Typecheck

Typecheck (RealTime.RealTime -> RealTime.RealTime) Source # 
Instance details

Defined in Derive.Typecheck

type TEnum a = (ShowVal.ShowVal a, Bounded a, Enum a) Source #

I can automatically derive a Typecheck for enum types. So a simple enum can get a Typecheck by "just" deriving these plus Typecheck.

class ToVal a where Source #

This is the inverse of Typecheck's from_val.

Minimal complete definition

Nothing

Methods

to_val :: a -> DeriveT.Val Source #

default to_val :: TEnum a => a -> DeriveT.Val Source #

Instances

Instances details
ToVal Attrs.Attributes Source # 
Instance details

Defined in Derive.Typecheck

ToVal KotekanStyle Source # 
Instance details

Defined in Derive.C.Bali.Gangsa

ToVal NorotStyle Source # 
Instance details

Defined in Derive.C.Bali.Gangsa

ToVal Adjust Source # 
Instance details

Defined in Derive.C.Prelude.Trill

ToVal Direction Source # 
Instance details

Defined in Derive.C.Prelude.Trill

ToVal Hand Source # 
Instance details

Defined in Derive.Call

ToVal UpDown Source # 
Instance details

Defined in Derive.Call

ToVal Speed Source # 
Instance details

Defined in Derive.Call.Speed

ToVal DeriveT.CFunction Source # 
Instance details

Defined in Derive.Typecheck

ToVal DeriveT.ControlRef Source # 
Instance details

Defined in Derive.Typecheck

ToVal DeriveT.Duration Source # 
Instance details

Defined in Derive.Typecheck

ToVal DeriveT.PControlRef Source # 
Instance details

Defined in Derive.Typecheck

ToVal DeriveT.PFunction Source # 
Instance details

Defined in Derive.Typecheck

ToVal DeriveT.PSignal Source # 
Instance details

Defined in Derive.Typecheck

ToVal DeriveT.Pitch Source # 
Instance details

Defined in Derive.Typecheck

ToVal DeriveT.Quoted Source # 
Instance details

Defined in Derive.Typecheck

ToVal DeriveT.Val Source # 
Instance details

Defined in Derive.Typecheck

ToVal Expr.Str Source # 
Instance details

Defined in Derive.Typecheck

ToVal Expr.Symbol Source # 
Instance details

Defined in Derive.Typecheck

ToVal ScoreT.Control Source # 
Instance details

Defined in Derive.Typecheck

ToVal ScoreT.Instrument Source # 
Instance details

Defined in Derive.Typecheck

ToVal ScoreT.PControl Source # 
Instance details

Defined in Derive.Typecheck

ToVal ScoreT.Type Source # 
Instance details

Defined in Derive.Typecheck

ToVal ScoreT.TypedSignal Source #

Signal.Control has ToVal but not Typecheck, because calls should be using Function.

Instance details

Defined in Derive.Typecheck

ToVal Dummy Source # 
Instance details

Defined in Derive.Sig

ToVal DefaultDiatonic Source # 
Instance details

Defined in Derive.Typecheck

ToVal DefaultReal Source # 
Instance details

Defined in Derive.Typecheck

ToVal DefaultScore Source # 
Instance details

Defined in Derive.Typecheck

ToVal Normalized Source # 
Instance details

Defined in Derive.Typecheck

ToVal NormalizedBipolar Source # 
Instance details

Defined in Derive.Typecheck

ToVal FreeCodePosition Source # 
Instance details

Defined in Perform.Lilypond.Constants

ToVal Pitch.NoteNumber Source # 
Instance details

Defined in Derive.Typecheck

ToVal Pitch.Pitch Source # 
Instance details

Defined in Derive.Typecheck

ToVal Pitch.Transpose Source # 
Instance details

Defined in Derive.Typecheck

ToVal RealTime.RealTime Source # 
Instance details

Defined in Derive.Typecheck

ToVal Meter.Rank Source # 
Instance details

Defined in Derive.Typecheck

ToVal ScoreTime.ScoreTime Source # 
Instance details

Defined in Derive.Typecheck

ToVal Text Source # 
Instance details

Defined in Derive.Typecheck

ToVal Integer Source # 
Instance details

Defined in Derive.Typecheck

ToVal Bool Source # 
Instance details

Defined in Derive.Typecheck

ToVal Double Source # 
Instance details

Defined in Derive.Typecheck

ToVal Int Source # 
Instance details

Defined in Derive.Typecheck

ToVal (Ratio.Ratio Int) Source # 
Instance details

Defined in Derive.Typecheck

ToVal a => ToVal (Set a) Source # 
Instance details

Defined in Derive.Typecheck

Methods

to_val :: Set a -> DeriveT.Val Source #

ToVal (Position CodePosition) Source # 
Instance details

Defined in Derive.Call.Ly

ToVal (ScoreT.Typed Signal.Y) Source # 
Instance details

Defined in Derive.Typecheck

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

Defined in Derive.Typecheck

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

Defined in Derive.Typecheck

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

Defined in Derive.Typecheck

ToVal a => ToVal [a] Source # 
Instance details

Defined in Derive.Typecheck

Methods

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

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

Defined in Derive.Typecheck

Methods

to_val :: Either a b -> DeriveT.Val Source #

class Typecheck a => TypecheckNum a where Source #

Instances

Instances details
TypecheckNum Speed Source # 
Instance details

Defined in Derive.Call.Speed

TypecheckNum DeriveT.Duration Source # 
Instance details

Defined in Derive.Typecheck

TypecheckNum DefaultDiatonic Source # 
Instance details

Defined in Derive.Typecheck

TypecheckNum DefaultReal Source # 
Instance details

Defined in Derive.Typecheck

TypecheckNum DefaultScore Source # 
Instance details

Defined in Derive.Typecheck

TypecheckNum Pitch.NoteNumber Source # 
Instance details

Defined in Derive.Typecheck

TypecheckNum Pitch.Transpose Source # 
Instance details

Defined in Derive.Typecheck

TypecheckNum RealTime.RealTime Source # 
Instance details

Defined in Derive.Typecheck

TypecheckNum ScoreTime.ScoreTime Source # 
Instance details

Defined in Derive.Typecheck

TypecheckNum Integer Source # 
Instance details

Defined in Derive.Typecheck

TypecheckNum Double Source # 
Instance details

Defined in Derive.Typecheck

TypecheckNum Int Source # 
Instance details

Defined in Derive.Typecheck

TypecheckNum (Ratio.Ratio Int) Source # 
Instance details

Defined in Derive.Typecheck

TypecheckNum (ScoreT.Typed Signal.Y) Source # 
Instance details

Defined in Derive.Typecheck

util

controls

coerce_to_scalar :: (ScoreT.Typed Signal.Y -> Maybe a) -> DeriveT.Val -> Checked a Source #

Coerce any numeric value to a ScoreT.Typed Signal.Y, and check it against the given function.

lookup_function :: DeriveT.ControlRef -> Derive.Deriver (Maybe ScoreT.TypedFunction) Source #

Resolve a ref to a function, applying a CFunction if there is one.

lookup_signal :: ScoreT.Control -> Derive.Deriver (Maybe ScoreT.TypedSignal) Source #

As with lookup_pitch_function, this should be in Deriver.Lib.

val_to_function_dyn :: DeriveT.Dynamic -> DeriveT.Val -> Maybe (Either (Derive.Deriver ScoreT.TypedFunction) ScoreT.TypedFunction) Source #

Unfortunately Internal.get_control_function_dynamic is non-trivial, so it makes sense to do it only once when converting many.

TODO does it really? It seems like a bogus tradeoff to have to make. I could cache it, but is that not what this is? If it's cheap to call Internal.get_control_function_dynamic and only expensive to force it, then I should always pass it, and rely on laziness.

pitch signals

lookup_pitch_signal :: ScoreT.PControl -> Derive.Deriver (Maybe DeriveT.PSignal) Source #

This should be in Deriver.Lib, but has to be here so the instance Typecheck PitchFunction can be declared here and avoid circular import.

resolve_pitch_ref :: DeriveT.PControlRef -> Derive.Deriver DeriveT.PSignal Source #

This is the pitch version of resolve_control_ref, except simpler because there's no pitch equivalent of CFunction.

compatibility

Orphan instances