#modify

Invocation

f :: (a: $A) -> $B #modify (A: ^Type_Info) -> <something> { <modify-code> } { <procedure-code> } - provide a function to manipulate a type variable prior to it being used in a polymorphic procedure. 1 2

See also:

Examples

Description

#modify injects a user-defined procedure at compile time to allow for validation, modification, or other arbitrary actions on the type variables being passed to a polymorhpic procedure.

The procedure can be defined inline:

foo :: (f: $T) -> $R
#modify (T : ^Type_Info, R : ^Type_Info) -> ^Type_Info, ^Type_Info { /* .. */ }
{
  // ..
}

Or named and shared:

ensure_R_is_big_enough :: (T : ^Type_Info, R : ^Type_Info) -> ^Type_Info, ^Type_Info { /* .. */ }

foo :: (f: $T) -> $R
#modify ensure_R_is_big_enough
{
  // ..
}

bar :: (b: $T) -> $R
#modify ensure_R_is_big_enough
{
  // ..
}

Multiple #modify procedures can be chained, and execute in order.

foo :: (a: $T) -> $R
#modify ensure_R_is_big_enough
#modify reject_R_if_float
{
  // ..
}

Examples:

toggle example
sum_modify.jai

  1. [..] this thing called a modify directive [..] you can attach it onto a polymorphic procedure, and it supplies code that runs at compile time that maps the types given by the user onto the types of the generated function.
    “Polymorphic Procedures, part 1” YouTube, uploaded by Jonathan Blow, Apr 1, 2015, https://youtu.be/BwqeFrlSpuI?t=2593 

  2. ..you can chain them together, and if you use more than one, they get called in order. So, [..] you could have a toolkit of them that you just apply.
    “Polymorphic Procedures, part 2” YouTube, uploaded by Jonathan Blow, Apr 1, 2015, https://youtu.be/7Fsy2WaxLOY?t=423 

jailang 2019 pixeldroid
https://github.com/pixeldroid/jailang
programming pages theme v0.5.21 (https://github.com/pixeldroid/programming-pages)