@@ -468,6 +468,45 @@ impl<'arena> RigidEnv<'arena> {
468468 env. define_prim ( Array32Find , array32_find_type) ;
469469 env. define_prim ( Array64Find , array64_find_type) ;
470470
471+ // fun (len : UN) -> (A : Type) -> (index : UN) -> ArrayN len A -> A
472+ // fun (len : UN) -> (A : Type) -> (index : UN) -> ArrayN len@2 A@1 -> A@2
473+ let array_index_type = |index_type, array_type| {
474+ scope. to_scope ( core:: Term :: FunType (
475+ Span :: Empty ,
476+ env. name ( "len" ) ,
477+ index_type,
478+ scope. to_scope ( core:: Term :: FunType (
479+ Span :: Empty ,
480+ env. name ( "A" ) ,
481+ & UNIVERSE ,
482+ scope. to_scope ( core:: Term :: FunType (
483+ Span :: Empty ,
484+ env. name ( "index" ) ,
485+ & index_type,
486+ scope. to_scope ( core:: Term :: FunType (
487+ Span :: Empty ,
488+ None ,
489+ // ArrayN len@2 A@1
490+ scope. to_scope ( Term :: FunApp (
491+ Span :: Empty ,
492+ scope. to_scope ( Term :: FunApp ( Span :: Empty , array_type, & VAR2 ) ) ,
493+ & VAR1 ,
494+ ) ) ,
495+ & VAR2 , // A@2
496+ ) ) ,
497+ ) ) ,
498+ ) ) ,
499+ ) )
500+ } ;
501+ let array8_index_type = array_index_type ( & U8_TYPE , & ARRAY8_TYPE ) ;
502+ let array16_index_type = array_index_type ( & U16_TYPE , & ARRAY16_TYPE ) ;
503+ let array32_index_type = array_index_type ( & U32_TYPE , & ARRAY32_TYPE ) ;
504+ let array64_index_type = array_index_type ( & U64_TYPE , & ARRAY64_TYPE ) ;
505+ env. define_prim ( Array8Index , array8_index_type) ;
506+ env. define_prim ( Array16Index , array16_index_type) ;
507+ env. define_prim ( Array32Index , array32_index_type) ;
508+ env. define_prim ( Array64Index , array64_index_type) ;
509+
471510 env. define_prim_fun ( PosAddU8 , [ & POS_TYPE , & U8_TYPE ] , & POS_TYPE ) ;
472511 env. define_prim_fun ( PosAddU16 , [ & POS_TYPE , & U16_TYPE ] , & POS_TYPE ) ;
473512 env. define_prim_fun ( PosAddU32 , [ & POS_TYPE , & U32_TYPE ] , & POS_TYPE ) ;
0 commit comments