Karya, built on 2022-03-21T01:30:44 (patch 89d1651424c35e564138d93424a157ff87457245)
Safe HaskellSafe-Inferred

Derive.Typecheck

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

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

Defined in Derive.C.Prelude.ControlFunction

Typecheck Adjust Source # 
Instance details

Defined in Derive.C.Prelude.Trill

Typecheck Direction Source # 
Instance details

Defined in Derive.C.Prelude.Trill

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

Defined in Derive.Typecheck

Typecheck DeriveT.ControlRef Source #

Use a TypedFunction or Function instead of this.

Instance details

Defined in Derive.Typecheck

Typecheck DeriveT.Duration Source # 
Instance details

Defined in Derive.Typecheck

Typecheck DeriveT.PControlRef Source # 
Instance details

Defined in Derive.Typecheck

Typecheck DeriveT.Pitch 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.Instrument Source # 
Instance details

Defined in Derive.Typecheck

Typecheck ScoreT.PControl 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 Function 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 TypedFunction 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 #

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 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 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

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

Defined in Derive.Call.Speed

ToVal DeriveT.ControlFunction 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.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 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 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

numeric types

num_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.

util

data TimeType Source #

Constructors

Real 
Score 

Instances

Instances details
Show TimeType Source # 
Instance details

Defined in Derive.Typecheck

Eq TimeType Source # 
Instance details

Defined in Derive.Typecheck

Pretty TimeType Source # 
Instance details

Defined in Derive.Typecheck

to_typed_function

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

Convert a DeriveT.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.

pitch_at :: RealTime.RealTime -> DeriveT.PControlRef -> Derive.Deriver DeriveT.Pitch Source #

This is the pitch signal version of to_signal_or_function, except simpler because there's no pitch equivalent of ControlFunction.

I could actually have a pitch version of Function, which I guess would be called PitchFunction, except be unlike ControlFunction, in that it actually is a function, where ControlFunction isn't. What a mess, I wish I could get rid of ControlFunction...

Orphan instances