Karya, built on 2020-11-26T21:03:17 (patch 23b5be2d53a9e8e7d6136cda5aae2849abe5cded)
Safe HaskellNone

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

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

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

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 # 
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 # 
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 Val. ToVal is the inverse transformation.

Minimal complete definition

Nothing

Instances

Instances details
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 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 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 Pitch.NoteNumber # 
Instance details

Defined in Derive.Typecheck

Typecheck Pitch.Pitch # 
Instance details

Defined in Derive.Typecheck

Typecheck Attrs.Attributes # 
Instance details

Defined in Derive.Typecheck

Typecheck Meter.RankName # 
Instance details

Defined in Derive.Typecheck

Typecheck ScoreT.PControl # 
Instance details

Defined in Derive.Typecheck

Typecheck ScoreT.Control # 
Instance details

Defined in Derive.Typecheck

Typecheck ScoreT.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 DeriveT.ControlFunction # 
Instance details

Defined in Derive.Typecheck

Typecheck DeriveT.PControlRef # 
Instance details

Defined in Derive.Typecheck

Typecheck DeriveT.ControlRef #

Use a TypedFunction or Function instead of this.

Instance details

Defined in Derive.Typecheck

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

Defined in Derive.Typecheck

Typecheck DeriveT.Duration # 
Instance details

Defined in Derive.Typecheck

Typecheck DeriveT.Pitch # 
Instance details

Defined in Derive.Typecheck

Typecheck Derive.PitchDeriver # 
Instance details

Defined in Derive.Sig

Typecheck Derive.ControlDeriver # 
Instance details

Defined in Derive.Sig

Typecheck Derive.NoteDeriver # 
Instance details

Defined in Derive.Sig

Typecheck SubT.Track # 
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 NormalizedBipolar # 
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] #

A non-list is coerced into a singleton list.

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 a, Ord a) => Typecheck (Set a) # 
Instance details

Defined in Derive.Typecheck

Typecheck (ScoreT.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

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 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 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 Attrs.Attributes # 
Instance details

Defined in Derive.Typecheck

ToVal ScoreT.PControl # 
Instance details

Defined in Derive.Typecheck

ToVal ScoreT.Control # 
Instance details

Defined in Derive.Typecheck

ToVal ScoreT.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 DeriveT.ControlFunction # 
Instance details

Defined in Derive.Typecheck

ToVal DeriveT.PControlRef # 
Instance details

Defined in Derive.Typecheck

ToVal DeriveT.ControlRef # 
Instance details

Defined in Derive.Typecheck

ToVal DeriveT.Quoted # 
Instance details

Defined in Derive.Typecheck

ToVal DeriveT.Val # 
Instance details

Defined in Derive.Typecheck

ToVal DeriveT.Duration # 
Instance details

Defined in Derive.Typecheck

ToVal DeriveT.Pitch # 
Instance details

Defined in Derive.Typecheck

ToVal DefaultDiatonic # 
Instance details

Defined in Derive.Typecheck

ToVal NormalizedBipolar # 
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] -> DeriveT.Val Source #

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

Defined in Derive.Typecheck

ToVal (Ratio.Ratio Int) # 
Instance details

Defined in Derive.Typecheck

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

Defined in Derive.Typecheck

Methods

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

ToVal (ScoreT.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

Methods

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

class Typecheck a => TypecheckNum a where Source #

Instances

Instances details
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 DeriveT.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 (ScoreT.Typed Signal.Y) # 
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
Eq TimeType # 
Instance details

Defined in Derive.Typecheck

Show TimeType # 
Instance details

Defined in Derive.Typecheck

Pretty TimeType # 
Instance details

Defined in Derive.Typecheck

data TransposeType Source #

Constructors

Diatonic 
Chromatic 
Nn 

Instances

Instances details
Eq TransposeType # 
Instance details

Defined in Derive.Typecheck

Show TransposeType # 
Instance details

Defined in Derive.Typecheck

Pretty TransposeType # 
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