/*---------------------------------------------------------------------------
  Copyright 2012-2024, Microsoft Research, Daan Leijen.

  This is free software; you can redistribute it and/or modify it under the
  terms of the Apache License, Version 2.0. A copy of the License can be
  found in the LICENSE file at the root of this distribution.
---------------------------------------------------------------------------*/

// Standard `:list` functions.
module std/core/liststd/core/list

import std/core/typesstd/core/types
import std/core/undivstd/core/undiv
import std/core/hndstd/core/hnd
import std/core/exnstd/core/exn
import std/core/charstd/core/char
import std/core/stringstd/core/string
import std/core/intstd/core/int
import std/core/vectorstd/core/vector


// Return the head of list if the list is not empty.
pub fun headstd/core/list/head: forall<a> (xs : list<a>) -> maybe<a>( xsxs: list<$562> : liststd/core/types/list: V -> V<aa: V> )result: -> total maybe<583> : maybestd/core/types/maybe: V -> V<aa: V>
  match xsxs: list<$562>
    Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $562) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $562)
    _       -> Nothingstd/core/types/Nothing: forall<a> maybe<a>

// Return the head of list with a default value in case the list is empty.
pub fun default/headstd/core/list/default/head: forall<a> (xs : list<a>, default : a) -> a( xsxs: list<$588> : liststd/core/types/list: V -> V<aa: V>, defaultdefault: $588 : aa: V )result: -> total 601 : astd/core/types/total: E
  match xsxs: list<$588>
    Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $588) -> xx: $588
    _       -> defaultdefault: $588

// Return the tail of list. Returns the empty list if `xs` is empty.
pub fun tailstd/core/list/tail: forall<a> (xs : list<a>) -> list<a>( xsxs: list<$606> : liststd/core/types/list: V -> V<aa: V> )result: -> total list<621> : liststd/core/types/list: V -> V<aa: V>
  match xsxs: list<$606>
    Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,xxxx: list<$606>) -> xxxx: list<$606>
    _          -> [std/core/types/Nil: forall<a> list<a>]std/core/types/Nil: forall<a> list<a>

// Is the list empty?
pub fun is-emptystd/core/list/is-empty: forall<a> (xs : list<a>) -> bool( xsxs: list<$626> : liststd/core/types/list: V -> V<aa: V> )result: -> total bool : boolstd/core/types/bool: V
  match xsxs: list<$626>
    Nilstd/core/types/Nil: forall<a> list<a> -> Truestd/core/types/True: bool
    _   -> Falsestd/core/types/False: bool


// ----------------------------------------------------------------------------
// List functions
// ----------------------------------------------------------------------------

// Returns a singleton list.
pub fun singlestd/core/list/single: forall<a> (x : a) -> list<a>(xx: _643)result: -> total list<$2278>
  [std/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>xx: _643]std/core/types/Nil: forall<a> list<a>

// Returns the length of a list.
pub fun lengthstd/core/list/length: forall<a> (xs : list<a>) -> int(xsxs: list<_693>)result: -> total int
  fun lenlen: forall<a> (ys : list<a>, acc : int) -> int(ysys: list<_673>,accacc: int)result: -> total int
    match ysys: list<_673>
      Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,yyyy: list<_673>) -> yyyy: list<_673>.lenlen: (ys : list<_673>, acc : int) -> int(accacc: int+std/core/int/(+): (x : int, y : int) -> int1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
) Nilstd/core/types/Nil: forall<a> list<a> -> accacc: int
xsxs: list<_693>.lenlen: (ys : list<_693>, acc : int) -> int(0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
) // Returns an integer list of increasing elements from `lo` to `hi` // (including both `lo` and `hi` ). // If `lo > hi` the function returns the empty list. pub fun liststd/core/list/list: (lo : int, hi : int) -> list<int>( lolo: int: intstd/core/types/int: V, hihi: int: intstd/core/types/int: V )result: -> total list<int> : totalstd/core/types/total: E liststd/core/types/list: V -> V<intstd/core/types/int: V> if lolo: int <=std/core/int/(<=): (x : int, y : int) -> bool hihi: int then Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>( lolo: int, liststd/core/list/list: (lo : int, hi : int) -> list<int>( pretend-decreasingstd/core/undiv/pretend-decreasing: (x : int) -> int(lolo: int.incstd/core/int/inc: (i : int) -> int), hihi: int ) ) else Nilstd/core/types/Nil: forall<a> list<a> // Returns an integer list of increasing elements from `lo` to `hi` with stride `stride`. // If `lo > hi` the function returns the empty list. pub fun stride/liststd/core/list/stride/list: (lo : int, hi : int, stride : int) -> list<int>( lolo: int: intstd/core/types/int: V, hihi: int: intstd/core/types/int: V, stridestride: int : intstd/core/types/int: V )result: -> total list<int> : totalstd/core/types/total: E liststd/core/types/list: V -> V<intstd/core/types/int: V> if lolo: int <=std/core/int/(<=): (x : int, y : int) -> bool hihi: int then Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>( lolo: int, liststd/core/list/stride/list: (lo : int, hi : int, stride : int) -> list<int>( pretend-decreasingstd/core/undiv/pretend-decreasing: (x : int) -> int(lolo: int +std/core/int/(+): (x : int, y : int) -> int stridestride: int), hihi: int, stridestride: int )) else Nilstd/core/types/Nil: forall<a> list<a> // Applies a function `f` to list of increasing elements from `lo` to `hi` // (including both `lo` and `hi` ). // If `lo > hi` the function returns the empty list. pub fun function/liststd/core/list/function/list: forall<a,e> (lo : int, hi : int, f : (int) -> e a) -> e list<a>( lolo: int: intstd/core/types/int: V, hihi: int: intstd/core/types/int: V, ff: (int) -> $1705 $1704 : intstd/core/types/int: V -> ee: E aa: V )result: -> 1755 list<1754> : ee: E liststd/core/types/list: V -> V<aa: V> if lolo: int <=std/core/int/(<=): (x : int, y : int) -> $1705 bool hihi: int then Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>( ff: (int) -> $1705 $1704(lolo: int), liststd/core/list/function/list: (lo : int, hi : int, f : (int) -> $1705 $1704) -> $1705 list<$1704>( pretend-decreasingstd/core/undiv/pretend-decreasing: (x : int) -> $1705 int(lolo: int.incstd/core/int/inc: (i : int) -> $1705 int), hihi: int, ff: (int) -> $1705 $1704 )) else Nilstd/core/types/Nil: forall<a> list<a> // Returns an integer list of increasing elements from `lo` to `hi` with stride `stride`. // If `lo > hi` the function returns the empty list. pub fun stridefunction/liststd/core/list/stridefunction/list: forall<a,e> (lo : int, hi : int, stride : int, f : (int) -> e a) -> e list<a>( lolo: int: intstd/core/types/int: V, hihi: int: intstd/core/types/int: V, stridestride: int : intstd/core/types/int: V, ff: (int) -> $1822 $1821 : intstd/core/types/int: V -> ee: E aa: V )result: -> 1874 list<1873> : ee: E liststd/core/types/list: V -> V<aa: V> if lolo: int <=std/core/int/(<=): (x : int, y : int) -> $1822 bool hihi: int then Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>( ff: (int) -> $1822 $1821(lolo: int), liststd/core/list/stridefunction/list: (lo : int, hi : int, stride : int, f : (int) -> $1822 $1821) -> $1822 list<$1821>( pretend-decreasingstd/core/undiv/pretend-decreasing: (x : int) -> $1822 int(lolo: int +std/core/int/(+): (x : int, y : int) -> $1822 int stridestride: int), hihi: int, stridestride: int, ff: (int) -> $1822 $1821 )) else Nilstd/core/types/Nil: forall<a> list<a> // Create a list of characters from `lo` to `hi` (including `hi`). pub fun char/liststd/core/list/char/list: (lo : char, hi : char) -> list<char>( lolo: char : charstd/core/types/char: V, hihi: char : charstd/core/types/char: V )result: -> total list<char> : totalstd/core/types/total: E liststd/core/types/list: V -> V<charstd/core/types/char: V> liststd/core/list/list: (lo : int, hi : int) -> list<int>(lolo: char.intstd/core/char/int: (char) -> int, hihi: char.intstd/core/char/int: (char) -> int).mapstd/core/list/map: (xs : list<int>, f : (int) -> char) -> list<char>( charstd/core/char/int/char: (i : int) -> char ) // Element-wise list equality pub fun (==)std/core/list/(==): forall<a> (xs : list<a>, ys : list<a>, @implicit/(==) : (a, a) -> bool) -> bool( xsxs: list<$702> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$702> : liststd/core/types/list: V -> V<aa: V>, (@implicit/==)?(==): ($702, $702) -> bool : (aa: V,aa: V) -> boolstd/core/types/bool: V )result: -> total bool : boolstd/core/types/bool: V match xsxs: list<$702> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $702,xxxx: list<$702>) -> match ysys: list<$702> Nilstd/core/types/Nil: forall<a> list<a> -> Falsestd/core/types/False: bool Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $702,yyyy: list<$702>) -> (xx: $702==?(==): ($702, $702) -> boolyy: $702) &&std/core/types/(&&): (x : bool, y : bool) -> bool (xxxx: list<$702>==std/core/list/(==): (xs : list<$702>, ys : list<$702>, @implicit/(==) : ($702, $702) -> bool) -> bool
?(==)=?(==)
yyyy: list<$702>) Nilstd/core/types/Nil: forall<a> list<a> -> match ysys: list<$702> Nilstd/core/types/Nil: forall<a> list<a> -> Truestd/core/types/True: bool Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a> -> Falsestd/core/types/False: bool
// Order on lists pub fun cmpstd/core/list/cmp: forall<a> (xs : list<a>, ys : list<a>, @implicit/cmp : (a, a) -> order) -> order( xsxs: list<$775> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$775> : liststd/core/types/list: V -> V<aa: V>, @implicit/cmp?cmp: ($775, $775) -> order : (aa: V,aa: V) -> orderstd/core/types/order: V )result: -> total order : orderstd/core/types/order: V match xsxs: list<$775> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $775,xxxx: list<$775>) -> match ysys: list<$775> Nilstd/core/types/Nil: forall<a> list<a> -> Gtstd/core/types/Gt: order Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $775,yyyy: list<$775>) -> match cmp?cmp: ($775, $775) -> order(xx: $775,yy: $775) Eqstd/core/types/Eq: order -> cmpstd/core/list/cmp: (xs : list<$775>, ys : list<$775>, @implicit/cmp : ($775, $775) -> order) -> order
?cmp=?cmp
(xxxx: list<$775>,yyyy: list<$775>) lglg: order -> lglg: order Nilstd/core/types/Nil: forall<a> list<a> -> match ysys: list<$775> Nilstd/core/types/Nil: forall<a> list<a> -> Eqstd/core/types/Eq: order Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a> -> Ltstd/core/types/Lt: order
// Show a list pub fun showstd/core/list/show: forall<a,e> (xs : list<a>, @implicit/show : (a) -> e string) -> e string( xsxs: list<$3056> : liststd/core/types/list: V -> V<aa: V>, @implicit/show?show: ($3056) -> $3057 string : aa: V -> ee: E stringstd/core/types/string: V )result: -> 3124 string : ee: E stringstd/core/types/string: V "["literal: string
count= 1
++std/core/types/(++): (x : string, y : string) -> $3057 string xsxs: list<$3056>.mapstd/core/list/map: (xs : list<$3056>, f : ($3056) -> $3057 string) -> $3057 list<string>(show?show: ($3056) -> $3057 string).joinstd/core/list/joinsep/join: (xs : list<string>, sep : string) -> $3057 string(","literal: string
count= 1
) ++std/core/types/(++): (x : string, y : string) -> $3057 string "]"literal: string
count= 1
// _deprecated_, use `list/show` instead. pub fun show-liststd/core/list/show-list: forall<a,e> (xs : list<a>, show-elem : (a) -> e string) -> e string( xsxs: list<$3141> : liststd/core/types/list: V -> V<aa: V>, show-elemshow-elem: ($3141) -> $3142 string : (aa: V) -> ee: E stringstd/core/types/string: V )result: -> 3159 string : ee: E stringstd/core/types/string: V showstd/core/list/show: (xs : list<$3141>, @implicit/show : ($3141) -> $3142 string) -> $3142 string(xsxs: list<$3141>,@implicit/show=show-elemshow-elem: ($3141) -> $3142 string) // Zip two lists together by pairing the corresponding elements. // The returned list is only as long as the smallest input list. pub fun zipstd/core/list/zip: forall<a,b> (xs : list<a>, ys : list<b>) -> list<(a, b)>( xsxs: list<$3166> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$3167> : liststd/core/types/list: V -> V<bb: V> )result: -> total list<(3222, 3223)> : liststd/core/types/list: V -> V<(std/core/types/tuple2: (V, V) -> Vaa: V,bb: V)> match xsxs: list<$3166> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $3166,xxxx: list<$3166>) -> match ysys: list<$3167> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $3167,yyyy: list<$3167>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>((std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)xx: $3166,yy: $3167)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b),zipstd/core/list/zip: (xs : list<$3166>, ys : list<$3167>) -> list<($3166, $3167)>(xxxx: list<$3166>,yyyy: list<$3167>)) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> // Zip two lists together by apply a function `f` to all corresponding elements. // The returned list is only as long as the smallest input list. pub fun zipwithstd/core/list/zipwith: forall<a,b,c,e> (xs : list<a>, ys : list<b>, f : (a, b) -> e c) -> e list<c>( xsxs: list<$3231> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$3232> :liststd/core/types/list: V -> V<bb: V>, ff: ($3231, $3232) -> $3234 $3233 : (aa: V,bb: V) -> ee: E cc: V )result: -> 3291 list<3290> : ee: E liststd/core/types/list: V -> V<cc: V> match xsxs: list<$3231> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $3231,xxxx: list<$3231>) -> match ysys: list<$3232> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $3232,yyyy: list<$3232>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: ($3231, $3232) -> $3234 $3233(xx: $3231,yy: $3232),zipwithstd/core/list/zipwith: (xs : list<$3231>, ys : list<$3232>, f : ($3231, $3232) -> $3234 $3233) -> $3234 list<$3233>(xxxx: list<$3231>,yyyy: list<$3232>,ff: ($3231, $3232) -> $3234 $3233)) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> _ -> Nilstd/core/types/Nil: forall<a> list<a> // Zip two lists together by apply a function `f` to all corresponding elements // and their index in the list. // The returned list is only as long as the smallest input list. pub fun zipwith-indexedstd/core/list/zipwith-indexed: forall<a,b,c,e> (xs0 : list<a>, ys0 : list<b>, f : (int, a, b) -> e c) -> e list<c>( xs0xs0: list<$3304> : liststd/core/types/list: V -> V<aa: V>, ys0ys0: list<$3305> :liststd/core/types/list: V -> V<bb: V>, ff: (int, $3304, $3305) -> $3307 $3306 : (intstd/core/types/int: V,aa: V,bb: V) -> ee: E cc: V )result: -> 3374 list<3373> : ee: E liststd/core/types/list: V -> V<cc: V> fun zipwith-iterzipwith-iter: (i : int, xs : list<$3304>, ys : list<$3305>) -> $3307 list<$3306>( ii: int, xsxs: list<$3304>, ysys: list<$3305> )result: -> $3307 list<$3306> match xsxs: list<$3304> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $3304,xxxx: list<$3304>) -> match ysys: list<$3305> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $3305,yyyy: list<$3305>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (int, $3304, $3305) -> $3307 $3306(ii: int,xx: $3304,yy: $3305),zipwith-iterzipwith-iter: (i : int, xs : list<$3304>, ys : list<$3305>) -> $3307 list<$3306>(ii: int+std/core/int/(+): (x : int, y : int) -> $3307 int1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
,xxxx: list<$3304>,yyyy: list<$3305>)) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a>
zipwith-iterzipwith-iter: (i : int, xs : list<$3304>, ys : list<$3305>) -> $3307 list<$3306>(0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
,xs0xs0: list<$3304>,ys0ys0: list<$3305>
) // Unzip a list of pairs into two lists pub fun unzipstd/core/list/unzip: forall<a,b> (xs : list<(a, b)>) -> (list<a>, list<b>)( xsxs: list<($3387, $3388)> : liststd/core/types/list: V -> V<(std/core/types/tuple2: (V, V) -> Vaa: V,bb: V)> )result: -> total (list<3565>, list<3566>) : (std/core/types/tuple2: (V, V) -> Vliststd/core/types/list: V -> V<aa: V>,liststd/core/types/list: V -> V<bb: V>) // todo: implement TRMC for multiple results fun iteriter: forall<a,b,c,d> (ys : list<(a, b)>, acc1 : cctx<c,list<a>>, acc2 : cctx<d,list<b>>) -> (c, d)( ysys: list<(_3402, _3403)>, acc1acc1: cctx<_3444,list<_3402>>, acc2acc2: cctx<_3484,list<_3403>> )result: -> total (_3444, _3484) match ysys: list<(_3402, _3403)> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>((std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)xx: _3402,yy: _3403)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b),xxxx: list<(_3402, _3403)>) -> iteriter: (ys : list<(_3402, _3403)>, acc1 : cctx<_3444,list<_3402>>, acc2 : cctx<_3484,list<_3403>>) -> (_3444, _3484)(xxxx: list<(_3402, _3403)>,acc1acc1: cctx<_3444,list<_3402>> ++std/core/types/cctx/(++): (c1 : cctx<_3444,list<_3402>>, c2 : cctx<list<_3402>,list<_3402>>) -> cctx<_3444,list<_3402>> ctxctx: cctx<list<_3402>,list<_3402>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: _3402,_hole: list<_3402>),acc2acc2: cctx<_3484,list<_3403>> ++std/core/types/cctx/(++): (c1 : cctx<_3484,list<_3403>>, c2 : cctx<list<_3403>,list<_3403>>) -> cctx<_3484,list<_3403>> ctxctx: cctx<list<_3403>,list<_3403>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: _3403,_hole: list<_3403>)) Nilstd/core/types/Nil: forall<a> list<a> -> (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)acc1acc1: cctx<_3444,list<_3402>> ++.std/core/types/cctx/(++.): (c : cctx<_3444,list<_3402>>, x : list<_3402>) -> _3444 Nilstd/core/types/Nil: forall<a> list<a>,acc2acc2: cctx<_3484,list<_3403>> ++.std/core/types/cctx/(++.): (c : cctx<_3484,list<_3403>>, x : list<_3403>) -> _3484 Nilstd/core/types/Nil: forall<a> list<a>)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) iteriter: (ys : list<($3387, $3388)>, acc1 : cctx<list<$3387>,list<$3387>>, acc2 : cctx<list<$3388>,list<$3388>>) -> (list<$3387>, list<$3388>)(xsxs: list<($3387, $3388)>,ctxctx: ctx<list<$3387>> _hole: list<$3387>,ctxctx: ctx<list<$3388>> _hole: list<$3388>) // Unzip a list of triples into three lists pub fun unzip3std/core/list/unzip3: forall<a,b,c> (xs : list<(a, b, c)>) -> (list<a>, list<b>, list<c>)( xsxs: list<($3574, $3575, $3576)> : liststd/core/types/list: V -> V<(std/core/types/tuple3: (V, V, V) -> Vaa: V,bb: V,cc: V)>)result: -> total (list<3828>, list<3829>, list<3830>) : (std/core/types/tuple3: (V, V, V) -> Vliststd/core/types/list: V -> V<aa: V>,liststd/core/types/list: V -> V<bb: V>,liststd/core/types/list: V -> V<cc: V>) // todo: implement TRMC for multiple results fun iteriter: forall<a,b,c,d,a1,b1> (ys : list<(a, b, c)>, acc1 : cctx<d,list<a>>, acc2 : cctx<a1,list<b>>, acc3 : cctx<b1,list<c>>) -> (d, a1, b1)( ysys: list<(_3592, _3593, _3594)>, acc1acc1: cctx<_3635,list<_3592>>, acc2acc2: cctx<_3675,list<_3593>>, acc3acc3: cctx<_3715,list<_3594>> )result: -> total (_3635, _3675, _3715) match ysys: list<(_3592, _3593, _3594)> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>((std/core/types/Tuple3: forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c)xx: _3592,yy: _3593,zz: _3594)std/core/types/Tuple3: forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c),xxxx: list<(_3592, _3593, _3594)>) -> iteriter: (ys : list<(_3592, _3593, _3594)>, acc1 : cctx<_3635,list<_3592>>, acc2 : cctx<_3675,list<_3593>>, acc3 : cctx<_3715,list<_3594>>) -> (_3635, _3675, _3715)(xxxx: list<(_3592, _3593, _3594)>,acc1acc1: cctx<_3635,list<_3592>> ++std/core/types/cctx/(++): (c1 : cctx<_3635,list<_3592>>, c2 : cctx<list<_3592>,list<_3592>>) -> cctx<_3635,list<_3592>> ctxctx: cctx<list<_3592>,list<_3592>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: _3592,_hole: list<_3592>),acc2acc2: cctx<_3675,list<_3593>> ++std/core/types/cctx/(++): (c1 : cctx<_3675,list<_3593>>, c2 : cctx<list<_3593>,list<_3593>>) -> cctx<_3675,list<_3593>> ctxctx: cctx<list<_3593>,list<_3593>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: _3593,_hole: list<_3593>),acc3acc3: cctx<_3715,list<_3594>> ++std/core/types/cctx/(++): (c1 : cctx<_3715,list<_3594>>, c2 : cctx<list<_3594>,list<_3594>>) -> cctx<_3715,list<_3594>> ctxctx: cctx<list<_3594>,list<_3594>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(zz: _3594,_hole: list<_3594>)) Nilstd/core/types/Nil: forall<a> list<a> -> (std/core/types/Tuple3: forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c)acc1acc1: cctx<_3635,list<_3592>> ++.std/core/types/cctx/(++.): (c : cctx<_3635,list<_3592>>, x : list<_3592>) -> _3635 Nilstd/core/types/Nil: forall<a> list<a>,acc2acc2: cctx<_3675,list<_3593>> ++.std/core/types/cctx/(++.): (c : cctx<_3675,list<_3593>>, x : list<_3593>) -> _3675 Nilstd/core/types/Nil: forall<a> list<a>,acc3acc3: cctx<_3715,list<_3594>> ++.std/core/types/cctx/(++.): (c : cctx<_3715,list<_3594>>, x : list<_3594>) -> _3715 Nilstd/core/types/Nil: forall<a> list<a>)std/core/types/Tuple3: forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c) iteriter: (ys : list<($3574, $3575, $3576)>, acc1 : cctx<list<$3574>,list<$3574>>, acc2 : cctx<list<$3575>,list<$3575>>, acc3 : cctx<list<$3576>,list<$3576>>) -> (list<$3574>, list<$3575>, list<$3576>)(xsxs: list<($3574, $3575, $3576)>,ctxctx: ctx<list<$3574>> _hole: list<$3574>,ctxctx: ctx<list<$3575>> _hole: list<$3575>,ctxctx: ctx<list<$3576>> _hole: list<$3576>) // Unzip a list of quadruples into four lists pub fun unzip4std/core/list/unzip4: forall<a,b,c,d> (xs : list<(a, b, c, d)>) -> (list<a>, list<b>, list<c>, list<d>)( xsxs: list<($3841, $3842, $3843, $3844)> : liststd/core/types/list: V -> V<(std/core/types/tuple4: (V, V, V, V) -> Vaa: V,bb: V,cc: V,dd: V)>)result: -> total (list<4171>, list<4172>, list<4173>, list<4174>) : (std/core/types/tuple4: (V, V, V, V) -> Vliststd/core/types/list: V -> V<aa: V>,liststd/core/types/list: V -> V<bb: V>,liststd/core/types/list: V -> V<cc: V>,liststd/core/types/list: V -> V<dd: V>) // todo: implement TRMC for multiple results fun iteriter: forall<a,b,c,d,a1,b1,c1,d1> (ys : list<(a, b, c, d)>, acc1 : cctx<a1,list<a>>, acc2 : cctx<b1,list<b>>, acc3 : cctx<c1,list<c>>, acc4 : cctx<d1,list<d>>) -> (a1, b1, c1, d1)( ysys: list<(_3862, _3863, _3864, _3865)>, acc1acc1: cctx<_3906,list<_3862>>, acc2acc2: cctx<_3946,list<_3863>>, acc3acc3: cctx<_3986,list<_3864>>, acc4acc4: cctx<_4026,list<_3865>> )result: -> total (_3906, _3946, _3986, _4026) match ysys: list<(_3862, _3863, _3864, _3865)> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>((std/core/types/Tuple4: forall<a,b,c,d> (fst : a, snd : b, thd : c, field4 : d) -> (a, b, c, d)xx: _3862,yy: _3863,zz: _3864,ww: _3865)std/core/types/Tuple4: forall<a,b,c,d> (fst : a, snd : b, thd : c, field4 : d) -> (a, b, c, d),xxxx: list<(_3862, _3863, _3864, _3865)>) -> iteriter: (ys : list<(_3862, _3863, _3864, _3865)>, acc1 : cctx<_3906,list<_3862>>, acc2 : cctx<_3946,list<_3863>>, acc3 : cctx<_3986,list<_3864>>, acc4 : cctx<_4026,list<_3865>>) -> (_3906, _3946, _3986, _4026)(xxxx: list<(_3862, _3863, _3864, _3865)>,acc1acc1: cctx<_3906,list<_3862>> ++std/core/types/cctx/(++): (c1 : cctx<_3906,list<_3862>>, c2 : cctx<list<_3862>,list<_3862>>) -> cctx<_3906,list<_3862>> ctxctx: cctx<list<_3862>,list<_3862>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: _3862,_hole: list<_3862>),acc2acc2: cctx<_3946,list<_3863>> ++std/core/types/cctx/(++): (c1 : cctx<_3946,list<_3863>>, c2 : cctx<list<_3863>,list<_3863>>) -> cctx<_3946,list<_3863>> ctxctx: cctx<list<_3863>,list<_3863>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: _3863,_hole: list<_3863>),acc3acc3: cctx<_3986,list<_3864>> ++std/core/types/cctx/(++): (c1 : cctx<_3986,list<_3864>>, c2 : cctx<list<_3864>,list<_3864>>) -> cctx<_3986,list<_3864>> ctxctx: cctx<list<_3864>,list<_3864>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(zz: _3864,_hole: list<_3864>),acc4acc4: cctx<_4026,list<_3865>> ++std/core/types/cctx/(++): (c1 : cctx<_4026,list<_3865>>, c2 : cctx<list<_3865>,list<_3865>>) -> cctx<_4026,list<_3865>> ctxctx: cctx<list<_3865>,list<_3865>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ww: _3865,_hole: list<_3865>)) Nilstd/core/types/Nil: forall<a> list<a> -> (std/core/types/Tuple4: forall<a,b,c,d> (fst : a, snd : b, thd : c, field4 : d) -> (a, b, c, d)acc1acc1: cctx<_3906,list<_3862>> ++.std/core/types/cctx/(++.): (c : cctx<_3906,list<_3862>>, x : list<_3862>) -> _3906 Nilstd/core/types/Nil: forall<a> list<a>,acc2acc2: cctx<_3946,list<_3863>> ++.std/core/types/cctx/(++.): (c : cctx<_3946,list<_3863>>, x : list<_3863>) -> _3946 Nilstd/core/types/Nil: forall<a> list<a>,acc3acc3: cctx<_3986,list<_3864>> ++.std/core/types/cctx/(++.): (c : cctx<_3986,list<_3864>>, x : list<_3864>) -> _3986 Nilstd/core/types/Nil: forall<a> list<a>,acc4acc4: cctx<_4026,list<_3865>> ++.std/core/types/cctx/(++.): (c : cctx<_4026,list<_3865>>, x : list<_3865>) -> _4026 Nilstd/core/types/Nil: forall<a> list<a>)std/core/types/Tuple4: forall<a,b,c,d> (fst : a, snd : b, thd : c, field4 : d) -> (a, b, c, d) iteriter: (ys : list<($3841, $3842, $3843, $3844)>, acc1 : cctx<list<$3841>,list<$3841>>, acc2 : cctx<list<$3842>,list<$3842>>, acc3 : cctx<list<$3843>,list<$3843>>, acc4 : cctx<list<$3844>,list<$3844>>) -> (list<$3841>, list<$3842>, list<$3843>, list<$3844>)(xsxs: list<($3841, $3842, $3843, $3844)>,ctxctx: ctx<list<$3841>> _hole: list<$3841>,ctxctx: ctx<list<$3842>> _hole: list<$3842>,ctxctx: ctx<list<$3843>> _hole: list<$3843>,ctxctx: ctx<list<$3844>> _hole: list<$3844>) // Take the first `n` elements of a list (or fewer if the list is shorter than `n`) pub fun takestd/core/list/take: forall<a> (xs : list<a>, n : int) -> list<a>( xsxs: list<$841> : liststd/core/types/list: V -> V<aa: V>, nn: int : intstd/core/types/int: V )result: -> total list<879> : liststd/core/types/list: V -> V<aa: V> match xsxs: list<$841> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $841,xxxx: list<$841>) | nn: int >std/core/int/(>): (x : int, y : int) -> bool 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
-> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $841, takestd/core/list/take: (xs : list<$841>, n : int) -> list<$841>(xxxx: list<$841>, nn: int -std/core/int/(-): (x : int, y : int) -> int 1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
)) _ -> Nilstd/core/types/Nil: forall<a> list<a>
// Drop the first `n` elements of a list (or fewer if the list is shorter than `n`) pub fun dropstd/core/list/drop: forall<a> (xs : list<a>, n : int) -> list<a>( xsxs: list<$884> : liststd/core/types/list: V -> V<aa: V>, nn: int : intstd/core/types/int: V )result: -> total list<913> : liststd/core/types/list: V -> V<aa: V> match xsxs: list<$884> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,xxxx: list<$884>) | nn: int >std/core/int/(>): (x : int, y : int) -> bool 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
-> dropstd/core/list/drop: (xs : list<$884>, n : int) -> list<$884>(xxxx: list<$884>, nn: int -std/core/int/(-): (x : int, y : int) -> int 1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
) _ -> xsxs: list<$884>
// Apply a function `f` to each element of the input list in sequence. pub fun mapstd/core/list/map: forall<a,b,e> (xs : list<a>, f : (a) -> e b) -> e list<b>(xsxs: list<$1923> : liststd/core/types/list: V -> V<aa: V>, ff: ($1923) -> $1925 $1924 : aa: V -> ee: E bb: V)result: -> 1970 list<1969> : ee: E liststd/core/types/list: V -> V<bb: V> match xsxs: list<$1923> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1923,xxxx: list<$1923>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: ($1923) -> $1925 $1924(xx: $1923), xxxx: list<$1923>.mapstd/core/list/map: (xs : list<$1923>, f : ($1923) -> $1925 $1924) -> $1925 list<$1924>(ff: ($1923) -> $1925 $1924)) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> // Apply a function `f` to each element of the input list in sequence where takes // both the index of the current element and the element itself as arguments. pub fun map-indexedstd/core/list/map-indexed: forall<a,b,e> (xs : list<a>, f : (idx : int, value : a) -> e b) -> e list<b>(xsxs: list<$2019> : liststd/core/types/list: V -> V<aa: V>, ff: (idx : int, value : $2019) -> $2021 $2020 : (idx : intstd/core/types/int: V, value : aa: V) -> ee: E bb: V)result: -> 2070 list<2069> : ee: E liststd/core/types/list: V -> V<bb: V> fun map-idxmap-idx: (ys : list<$2019>, i : int) -> $2021 list<$2020>(ysys: list<$2019>,ii: int)result: -> $2021 list<$2020> match ysys: list<$2019> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2019,yyyy: list<$2019>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (idx : int, value : $2019) -> $2021 $2020(ii: int,yy: $2019), map-idxmap-idx: (ys : list<$2019>, i : int) -> $2021 list<$2020>(yyyy: list<$2019>,ii: int+std/core/int/(+): (x : int, y : int) -> $2021 int1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
)) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a>
map-idxmap-idx: (ys : list<$2019>, i : int) -> $2021 list<$2020>(xsxs: list<$2019>,0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
) // Apply a function `f` to each element of the input list in sequence where `f` takes // both the current element and the tail list as arguments. pub fun map-peekstd/core/list/map-peek: forall<a,b,e> (xs : list<a>, f : (value : a, rest : list<a>) -> e b) -> e list<b>(xsxs: list<$2080> : liststd/core/types/list: V -> V<aa: V>, ff: (value : $2080, rest : list<$2080>) -> $2082 $2081 : (value : aa: V, rest : liststd/core/types/list: V -> V<aa: V>) -> ee: E bb: V)result: -> 2122 list<2121> : ee: E liststd/core/types/list: V -> V<bb: V> fun mappeekmappeek: (ys : list<$2080>) -> $2082 list<$2081>(ysys: list<$2080>)result: -> $2082 list<$2081> match ysys: list<$2080> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2080,yyyy: list<$2080>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (value : $2080, rest : list<$2080>) -> $2082 $2081(yy: $2080,yyyy: list<$2080>), yyyy: list<$2080>.mappeekmappeek: (ys : list<$2080>) -> $2082 list<$2081>) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> mappeekmappeek: (ys : list<$2080>) -> $2082 list<$2081>(xsxs: list<$2080>) // Apply a function `f` to each element of the input list in sequence where takes // both the index of the current element, the element itself, and the tail list as arguments. pub fun map-indexed-peekstd/core/list/map-indexed-peek: forall<a,b,e> (xs : list<a>, f : (idx : int, value : a, rest : list<a>) -> e b) -> e list<b>(xsxs: list<$2132> : liststd/core/types/list: V -> V<aa: V>, ff: (idx : int, value : $2132, rest : list<$2132>) -> $2134 $2133 : (idx : intstd/core/types/int: V, value : aa: V, rest : liststd/core/types/list: V -> V<aa: V> ) -> ee: E bb: V)result: -> 2184 list<2183> : ee: E liststd/core/types/list: V -> V<bb: V> fun mapidxmapidx: (ys : list<$2132>, i : int) -> $2134 list<$2133>(ysys: list<$2132>,ii: int)result: -> $2134 list<$2133> match ysys: list<$2132> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2132,yyyy: list<$2132>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (idx : int, value : $2132, rest : list<$2132>) -> $2134 $2133(ii: int,yy: $2132,yyyy: list<$2132>), mapidxmapidx: (ys : list<$2132>, i : int) -> $2134 list<$2133>(yyyy: list<$2132>,ii: int+std/core/int/(+): (x : int, y : int) -> $2134 int1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
)) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a>
mapidxmapidx: (ys : list<$2132>, i : int) -> $2134 list<$2133>(xsxs: list<$2132>,0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
) // Reverse a list. pub fun reversestd/core/list/reverse: forall<a> (xs : list<a>) -> list<a>(xsxs: list<$968> : liststd/core/types/list: V -> V<aa: V>)result: -> total list<983> : liststd/core/types/list: V -> V<aa: V> reverse-appendstd/core/list/reverse-append: (xs : list<$968>, tl : list<$968>) -> list<$968>( xsxs: list<$968>, Nilstd/core/types/Nil: forall<a> list<a> ) // Efficiently reverse a list `xs` and append it to `tl`: // `reverse-append(xs,tl) == reserve(xs) ++ tl pub fun reverse-appendstd/core/list/reverse-append: forall<a> (xs : list<a>, tl : list<a>) -> list<a>( xsxs: list<$918> : liststd/core/types/list: V -> V<aa: V>, tltl: list<$918> : liststd/core/types/list: V -> V<aa: V> )result: -> total list<963> : liststd/core/types/list: V -> V<aa: V> fun reverse-accreverse-acc: forall<a> (acc : list<a>, ys : list<a>) -> list<a>(accacc: list<$919> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$919> : liststd/core/types/list: V -> V<aa: V> )result: -> total list<946> : liststd/core/types/list: V -> V<aa: V> match ysys: list<$919> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $919,xxxx: list<$919>) -> reverse-accreverse-acc: (acc : list<$919>, ys : list<$919>) -> list<$919>(Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $919,accacc: list<$919>),xxxx: list<$919>) _ -> accacc: list<$919> reverse-accreverse-acc: (acc : list<$918>, ys : list<$918>) -> list<$918>(tltl: list<$918>,xsxs: list<$918>) // Append two lists. pub fun (++)std/core/list/(++): forall<a> (xs : list<a>, ys : list<a>) -> list<a>(xsxs: list<$1021> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$1021> : liststd/core/types/list: V -> V<aa: V> )result: -> total list<1034> : liststd/core/types/list: V -> V<aa: V> appendstd/core/list/append: (xs : list<$1021>, ys : list<$1021>) -> list<$1021>(xsxs: list<$1021>,ysys: list<$1021>) // Append two lists. pub fun appendstd/core/list/append: forall<a> (xs : list<a>, ys : list<a>) -> list<a>(xsxs: list<$988> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$988> : liststd/core/types/list: V -> V<aa: V> )result: -> total list<1016> : liststd/core/types/list: V -> V<aa: V> match xsxs: list<$988> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $988,xxxx: list<$988>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $988,appendstd/core/list/append: (xs : list<$988>, ys : list<$988>) -> list<$988>(xxxx: list<$988>,ysys: list<$988>)) Nilstd/core/types/Nil: forall<a> list<a> -> ysys: list<$988> // Fold a list from the right, i.e. `foldr([1,2],0,(+)) == 1+(2+0)` // Note, `foldr` is less efficient than `foldl` as it reverses the list first. pub fun foldrstd/core/list/foldr: forall<a,b,e> (xs : list<a>, z : b, f : (a, b) -> e b) -> e b(xsxs: list<$1084> : liststd/core/types/list: V -> V<aa: V>, zz: $1085 : bb: V, ff: ($1084, $1085) -> $1086 $1085 : (aa: V, bb: V) -> ee: E bb: V)result: -> 1118 1117 : ee: E bb: V xsxs: list<$1084>.reversestd/core/list/reverse: (xs : list<$1084>) -> $1086 list<$1084>.foldlstd/core/list/foldl: (xs : list<$1084>, z : $1085, f : ($1085, $1084) -> $1086 $1085) -> $1086 $1085(zz: $1085) fnfn: (x : $1085, y : $1084) -> $1086 $1085(xx: $1085,yy: $1084) ff: ($1084, $1085) -> $1086 $1085(yy: $1084,xx: $1085) // Fold a list from the left, i.e. `foldl([1,2],0,(+)) == (0+1)+2` // Since `foldl` is tail recursive, it is preferred over `foldr` when using an associative function `f` pub fun foldlstd/core/list/foldl: forall<a,b,e> (xs : list<a>, z : b, f : (b, a) -> e b) -> e b(xsxs: list<$1039> : liststd/core/types/list: V -> V<aa: V>, zz: $1040 : bb: V, ff: ($1040, $1039) -> $1041 $1040 : (bb: V, aa: V) -> ee: E bb: V)result: -> 1074 1073 : ee: E bb: V match xsxs: list<$1039> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1039,xxxx: list<$1039>) -> foldlstd/core/list/foldl: (xs : list<$1039>, z : $1040, f : ($1040, $1039) -> $1041 $1040) -> $1041 $1040(xxxx: list<$1039>,ff: ($1040, $1039) -> $1041 $1040(zz: $1040,xx: $1039),ff: ($1040, $1039) -> $1041 $1040) Nilstd/core/types/Nil: forall<a> list<a> -> zz: $1040 pub fun foldl1std/core/list/foldl1: forall<a,e> (xs : list<a>, f : (a, a) -> <exn|e> a) -> <exn|e> a(xsxs: list<$1128> : liststd/core/types/list: V -> V<aa: V>, ff: ($1128, $1128) -> <exn|$1129> $1128 : (aa: V,aa: V) -> <exnstd/core/exn/exn: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V)result: -> <exn|1166> 1165 : <exnstd/core/exn/exn: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V match xsxs: list<$1128> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1128,xxxx: list<$1128>) -> xxxx: list<$1128>.foldlstd/core/list/foldl: (xs : list<$1128>, z : $1128, f : ($1128, $1128) -> <exn|$1129> $1128) -> <exn|$1129> $1128(xx: $1128,ff: ($1128, $1128) -> <exn|$1129> $1128) Nilstd/core/types/Nil: forall<a> list<a> -> throwstd/core/exn/throw: (message : string, info : ? exception-info) -> <exn|$1129> $1128("unexpected Nil in std/core/foldl1"literal: string
count= 33
) pub fun foldr1std/core/list/foldr1: forall<a,e> (xs : list<a>, f : (a, a) -> <exn|e> a) -> <exn|e> a(xsxs: list<$1173> : liststd/core/types/list: V -> V<aa: V>, ff: ($1173, $1173) -> <exn|$1174> $1173 : (aa: V,aa: V) -> <exnstd/core/exn/exn: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V)result: -> <exn|1196> 1195 : <exnstd/core/exn/exn: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V xsxs: list<$1173>.reversestd/core/list/reverse: (xs : list<$1173>) -> <exn|$1174> list<$1173>.foldl1std/core/list/foldl1: (xs : list<$1173>, f : ($1173, $1173) -> <exn|$1174> $1173) -> <exn|$1174> $1173(ff: ($1173, $1173) -> <exn|$1174> $1173) // Create a list of `n` repeated elements `x` pub fun replicatestd/core/list/replicate: forall<a> (x : a, n : int) -> list<a>( xx: $2194 : aa: V, nn: int : intstd/core/types/int: V )result: -> total list<2235> : liststd/core/types/list: V -> V<aa: V> if nn: int >std/core/int/(>): (x : int, y : int) -> bool 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
then Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2194, replicatestd/core/list/replicate: (x : $2194, n : int) -> list<$2194>(xx: $2194,pretend-decreasingstd/core/undiv/pretend-decreasing: (x : int) -> int(nn: int.decstd/core/int/dec: (i : int) -> int))) else Nilstd/core/types/Nil: forall<a> list<a>
// split a list at position `n` pub fun splitstd/core/list/split: forall<a> (xs : list<a>, n : int) -> (list<a>, list<a>)( xsxs: list<$1203> : liststd/core/types/list: V -> V<aa: V>, nn: int : intstd/core/types/int: V )result: -> total (list<1233>, list<1233>) : (std/core/types/tuple2: (V, V) -> Vliststd/core/types/list: V -> V<aa: V>, liststd/core/types/list: V -> V<aa: V>) (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)xsxs: list<$1203>.takestd/core/list/take: (xs : list<$1203>, n : int) -> list<$1203>(nn: int), xsxs: list<$1203>.dropstd/core/list/drop: (xs : list<$1203>, n : int) -> list<$1203>(nn: int))std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) pub fun spanstd/core/list/span: forall<a,e> (xs : list<a>, predicate : (a) -> e bool) -> e (list<a>, list<a>)( xsxs: list<$4188> : liststd/core/types/list: V -> V<aa: V>, predicatepredicate: ($4188) -> $4189 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 4265 (list<4264>, list<4264>) : ee: E (std/core/types/tuple2: (V, V) -> Vliststd/core/types/list: V -> V<aa: V>,liststd/core/types/list: V -> V<aa: V>) // todo: implement TRMC with multiple results to avoid the reverse fun span-accspan-acc: (ys : list<$4188>, acc : list<$4188>) -> $4189 (list<$4188>, list<$4188>)( ysys: list<$4188>, accacc: list<$4188>)result: -> $4189 (list<$4188>, list<$4188>) match ysys: list<$4188> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $4188,yyyy: list<$4188>) -> if yy: $4188.predicatepredicate: ($4188) -> $4189 bool then yyyy: list<$4188>.span-accspan-acc: (ys : list<$4188>, acc : list<$4188>) -> $4189 (list<$4188>, list<$4188>)(Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $4188,accacc: list<$4188>)) else (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)accacc: list<$4188>.reversestd/core/list/reverse: (xs : list<$4188>) -> $4189 list<$4188>,ysys: list<$4188>)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) _ -> (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)accacc: list<$4188>.reversestd/core/list/reverse: (xs : list<$4188>) -> $4189 list<$4188>, ysys: list<$4188>)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) xsxs: list<$4188>.span-accspan-acc: (ys : list<$4188>, acc : list<$4188>) -> $4189 (list<$4188>, list<$4188>)( [std/core/types/Nil: forall<a> list<a>]std/core/types/Nil: forall<a> list<a> ) // Keep only those initial elements that satisfy `predicate` pub fun take-whilestd/core/list/take-while: forall<a,e> (xs : list<a>, predicate : (a) -> e bool) -> e list<a>( xsxs: list<$4272> : liststd/core/types/list: V -> V<aa: V>, predicatepredicate: ($4272) -> $4273 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 4314 list<4313> : ee: E liststd/core/types/list: V -> V<aa: V> match xsxs: list<$4272> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $4272,xxxx: list<$4272>) -> if xx: $4272.predicatepredicate: ($4272) -> $4273 bool then Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $4272, xxxx: list<$4272>.take-whilestd/core/list/take-while: (xs : list<$4272>, predicate : ($4272) -> $4273 bool) -> $4273 list<$4272>(predicatepredicate: ($4272) -> $4273 bool) ) else Nilstd/core/types/Nil: forall<a> list<a> Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> // Drop all initial elements that satisfy `predicate` pub fun drop-whilestd/core/list/drop-while: forall<a,e> (xs : list<a>, predicate : (a) -> e bool) -> e list<a>( xsxs: list<$1238> : liststd/core/types/list: V -> V<aa: V>, predicatepredicate: ($1238) -> $1239 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 1271 list<1270> : ee: E liststd/core/types/list: V -> V<aa: V> match xsxs: list<$1238> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1238,xxxx: list<$1238>) -> if xx: $1238.predicatepredicate: ($1238) -> $1239 bool then xxxx: list<$1238>.drop-whilestd/core/list/drop-while: (xs : list<$1238>, predicate : ($1238) -> $1239 bool) -> $1239 list<$1238>(predicatepredicate: ($1238) -> $1239 bool) else xsxs: list<$1238> Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> // Retain only those elements of a list that satisfy the given predicate `pred`. // For example: `filter([1,2,3],odd?) == [1,3]` pub fun filterstd/core/list/filter: forall<a,e> (xs : list<a>, pred : (a) -> e bool) -> e list<a>( xsxs: list<$1278> : liststd/core/types/list: V -> V<aa: V>, predpred: ($1278) -> $1279 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 1326 list<1325> : ee: E liststd/core/types/list: V -> V<aa: V> match xsxs: list<$1278> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1278,xxxx: list<$1278>) -> if predpred: ($1278) -> $1279 bool(xx: $1278) then Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1278,xxxx: list<$1278>.filterstd/core/list/filter: (xs : list<$1278>, pred : ($1278) -> $1279 bool) -> $1279 list<$1278>(predpred: ($1278) -> $1279 bool)) else xxxx: list<$1278>.filterstd/core/list/filter: (xs : list<$1278>, pred : ($1278) -> $1279 bool) -> $1279 list<$1278>(predpred: ($1278) -> $1279 bool) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> // Remove those elements of a list that satisfy the given predicate `pred`. // For example: `remove([1,2,3],odd?) == [2]` pub fun removestd/core/list/remove: forall<a,e> (xs : list<a>, pred : (a) -> e bool) -> e list<a>( xsxs: list<$2240> : liststd/core/types/list: V -> V<aa: V>, predpred: ($2240) -> $2241 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 2270 list<2269> : ee: E liststd/core/types/list: V -> V<aa: V> xsxs: list<$2240>.filterstd/core/list/filter: (xs : list<$2240>, pred : ($2240) -> $2241 bool) -> $2241 list<$2240>( fnfn: (x : $2240) -> $2241 bool(xx: $2240) !std/core/types/bool/(!): (b : bool) -> $2241 boolpredpred: ($2240) -> $2241 bool(xx: $2240) ) // Partition a list in two lists where the first list contains // those elements that satisfy the given predicate `pred`. // For example: `partition([1,2,3],odd?) == ([1,3],[2])` pub fun partitionstd/core/list/partition: forall<a,e> (xs : list<a>, pred : (a) -> e bool) -> e (list<a>, list<a>)( xsxs: list<$2421> : liststd/core/types/list: V -> V<aa: V>, ^predpred: ($2421) -> $2422 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 2454 (list<2453>, list<2453>) : ee: E (std/core/types/tuple2: (V, V) -> Vliststd/core/types/list: V -> V<aa: V>,liststd/core/types/list: V -> V<aa: V>) partition-accstd/core/list/partition-acc: (xs : list<$2421>, pred : ($2421) -> $2422 bool, acc1 : ctx<list<$2421>>, acc2 : ctx<list<$2421>>) -> $2422 (list<$2421>, list<$2421>)(xsxs: list<$2421>, predpred: ($2421) -> $2422 bool, ctxctx: ctx<list<$2421>> _hole: list<$2421>, ctxctx: ctx<list<$2421>> _hole: list<$2421>) fun partition-accstd/core/list/partition-acc: forall<a,e> (xs : list<a>, pred : (a) -> e bool, acc1 : ctx<list<a>>, acc2 : ctx<list<a>>) -> e (list<a>, list<a>)(xsxs: list<$2277> : liststd/core/types/list: V -> V<aa: V>, ^predpred: ($2277) -> $2278 bool : aa: V -> ee: E boolstd/core/types/bool: V, acc1acc1: ctx<list<$2277>> : ctxstd/core/types/ctx: V -> V<liststd/core/types/list: V -> V<aa: V>>, acc2acc2: ctx<list<$2277>> : ctxstd/core/types/ctx: V -> V<liststd/core/types/list: V -> V<aa: V>>)result: -> 2414 (list<2413>, list<2413>): ee: E (std/core/types/tuple2: (V, V) -> Vliststd/core/types/list: V -> V<aa: V>, liststd/core/types/list: V -> V<aa: V>) match xsxs: list<$2277> Nilstd/core/types/Nil: forall<a> list<a> -> (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)acc1acc1: ctx<list<$2277>> ++.std/core/types/cctx/(++.): (c : cctx<list<$2277>,list<$2277>>, x : list<$2277>) -> $2278 list<$2277> Nilstd/core/types/Nil: forall<a> list<a>, acc2acc2: ctx<list<$2277>> ++.std/core/types/cctx/(++.): (c : cctx<list<$2277>,list<$2277>>, x : list<$2277>) -> $2278 list<$2277> Nilstd/core/types/Nil: forall<a> list<a>)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2277,xxxx: list<$2277>) -> if predpred: ($2277) -> $2278 bool(xx: $2277) then partition-accstd/core/list/partition-acc: (xs : list<$2277>, pred : ($2277) -> $2278 bool, acc1 : ctx<list<$2277>>, acc2 : ctx<list<$2277>>) -> $2278 (list<$2277>, list<$2277>)(xxxx: list<$2277>,predpred: ($2277) -> $2278 bool,acc1acc1: ctx<list<$2277>> ++std/core/types/cctx/(++): (c1 : cctx<list<$2277>,list<$2277>>, c2 : cctx<list<$2277>,list<$2277>>) -> $2278 cctx<list<$2277>,list<$2277>> ctxctx: cctx<list<$2277>,list<$2277>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2277,_hole: list<$2277>),acc2acc2: ctx<list<$2277>>) else partition-accstd/core/list/partition-acc: (xs : list<$2277>, pred : ($2277) -> $2278 bool, acc1 : ctx<list<$2277>>, acc2 : ctx<list<$2277>>) -> $2278 (list<$2277>, list<$2277>)(xxxx: list<$2277>,predpred: ($2277) -> $2278 bool,acc1acc1: ctx<list<$2277>>,acc2acc2: ctx<list<$2277>> ++std/core/types/cctx/(++): (c1 : cctx<list<$2277>,list<$2277>>, c2 : cctx<list<$2277>,list<$2277>>) -> $2278 cctx<list<$2277>,list<$2277>> ctxctx: cctx<list<$2277>,list<$2277>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2277,_hole: list<$2277>)) // Retain only those elements of a list that satisfy the given predicate `pred`. // For example: `filterMap([1,2,3],fn(i) { if i.odd? then Nothing else Just(i*i) }) == [4]` pub fun filter-mapstd/core/list/filter-map: forall<a,b,e> (xs : list<a>, pred : (a) -> e maybe<b>) -> e list<b>( xsxs: list<$1333> : liststd/core/types/list: V -> V<aa: V>, predpred: ($1333) -> $1335 maybe<$1334> : aa: V -> ee: E maybestd/core/types/maybe: V -> V<bb: V> )result: -> 1394 list<1393> : ee: E liststd/core/types/list: V -> V<bb: V> match xsxs: list<$1333> Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1333,xxxx: list<$1333>) -> match predpred: ($1333) -> $1335 maybe<$1334>(xx: $1333) Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<$1333>.filter-mapstd/core/list/filter-map: (xs : list<$1333>, pred : ($1333) -> $1335 maybe<$1334>) -> $1335 list<$1334>(predpred: ($1333) -> $1335 maybe<$1334>) Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $1334) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $1334,xxxx: list<$1333>.filter-mapstd/core/list/filter-map: (xs : list<$1333>, pred : ($1333) -> $1335 maybe<$1334>) -> $1335 list<$1334>(predpred: ($1333) -> $1335 maybe<$1334>)) // Find the first element satisfying some predicate pub fun findstd/core/list/find: forall<a,e> (xs : list<a>, pred : (a) -> e bool) -> e maybe<a>( xsxs: list<$1471> : liststd/core/types/list: V -> V<aa: V>, predpred: ($1471) -> $1472 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 1516 maybe<1515> : ee: E maybestd/core/types/maybe: V -> V<aa: V> xsxs: list<$1471>.foreach-whilestd/core/list/foreach-while: (xs : list<$1471>, action : ($1471) -> $1472 maybe<$1471>) -> $1472 maybe<$1471> fnfn: (x : $1471) -> $1472 maybe<$1471>(xx: $1471) if predpred: ($1471) -> $1472 bool(xx: $1471) then Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $1471) else Nothingstd/core/types/Nothing: forall<a> maybe<a> // Find the first element satisfying some predicate and return it. pub fun find-maybestd/core/list/find-maybe: forall<a,b,e> (xs : list<a>, pred : (a) -> e maybe<b>) -> e maybe<b>( xsxs: list<$1523> : liststd/core/types/list: V -> V<aa: V>, predpred: ($1523) -> $1525 maybe<$1524> : aa: V -> ee: E maybestd/core/types/maybe: V -> V<bb: V> )result: -> 1557 maybe<1556> : ee: E maybestd/core/types/maybe: V -> V<bb: V> xsxs: list<$1523>.foreach-whilestd/core/list/foreach-while: (xs : list<$1523>, action : ($1523) -> $1525 maybe<$1524>) -> $1525 maybe<$1524>(predpred: ($1523) -> $1525 maybe<$1524>) // Lookup the first element satisfying some predicate pub fun lookupstd/core/list/lookup: forall<a,b,e> (xs : list<(a, b)>, pred : (a) -> e bool) -> e maybe<b>( xsxs: list<($2461, $2462)> : liststd/core/types/list: V -> V<(std/core/types/tuple2: (V, V) -> Vaa: V,bb: V)>, predpred: ($2461) -> $2463 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 2580 maybe<2579> : ee: E maybestd/core/types/maybe: V -> V<bb: V> xsxs: list<($2461, $2462)>.foreach-whilestd/core/list/foreach-while: (xs : list<($2461, $2462)>, action : (($2461, $2462)) -> $2463 maybe<$2462>) -> $2463 maybe<$2462> fnfn: (kv : ($2461, $2462)) -> $2463 maybe<$2462>(kvkv: ($2461, $2462)) if predpred: ($2461) -> $2463 bool(kvkv: ($2461, $2462).fststd/core/types/tuple2/fst: (tuple2 : ($2461, $2462)) -> $2463 $2461) then Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(kvkv: ($2461, $2462).sndstd/core/types/tuple2/snd: (tuple2 : ($2461, $2462)) -> $2463 $2462) else Nothingstd/core/types/Nothing: forall<a> maybe<a> // Convert a `:maybe` type to a list type. pub fun maybe/liststd/core/list/maybe/list: forall<a> (m : maybe<a>) -> list<a>( mm: maybe<$1567> : maybestd/core/types/maybe: V -> V<aa: V> )result: -> total list<1592> : liststd/core/types/list: V -> V<aa: V> match mm: maybe<$1567> Nothingstd/core/types/Nothing: forall<a> maybe<a> -> Nilstd/core/types/Nil: forall<a> list<a> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $1567) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1567,Nilstd/core/types/Nil: forall<a> list<a>) fun index-of-accstd/core/list/index-of-acc: forall<a,e> (xs : list<a>, pred : (a) -> e bool, idx : int) -> e int( xsxs: list<$2590> : liststd/core/types/list: V -> V<aa: V>, predpred: ($2590) -> $2591 bool : aa: V -> ee: E boolstd/core/types/bool: V, idxidx: int : intstd/core/types/int: V )result: -> 2626 int : ee: E intstd/core/types/int: V match xsxs: list<$2590> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2590,xxxx: list<$2590>) -> if predpred: ($2590) -> $2591 bool(xx: $2590) then idxidx: int else index-of-accstd/core/list/index-of-acc: (xs : list<$2590>, pred : ($2590) -> $2591 bool, idx : int) -> $2591 int(xxxx: list<$2590>,predpred: ($2590) -> $2591 bool,idxidx: int+std/core/int/(+): (x : int, y : int) -> $2591 int1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
) Nilstd/core/types/Nil: forall<a> list<a> -> -1literal: int
dec = -1
hex8 = 0xFF
bit8 = 0b11111111
// Returns the index of the first element where `pred` holds, or `-1` if no such element exists. pub fun index-ofstd/core/list/index-of: forall<a,e> (xs : list<a>, pred : (a) -> e bool) -> e int( xsxs: list<$2633> : liststd/core/types/list: V -> V<aa: V>, predpred: ($2633) -> $2634 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 2651 int : ee: E intstd/core/types/int: V index-of-accstd/core/list/index-of-acc: (xs : list<$2633>, pred : ($2633) -> $2634 bool, idx : int) -> $2634 int( xsxs: list<$2633>, predpred: ($2633) -> $2634 bool, 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
) // Invoke `action` for each element of a list pub fun foreachstd/core/list/foreach: forall<a,e> (xs : list<a>, action : (a) -> e ()) -> e ()( xsxs: list<$2658> : liststd/core/types/list: V -> V<aa: V>, actionaction: ($2658) -> $2659 () : (aa: V) -> ee: E (std/core/types/unit: V)std/core/types/unit: V )result: -> 2692 () : ee: E (std/core/types/unit: V)std/core/types/unit: V match xsxs: list<$2658> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2658,xxxx: list<$2658>) -> { actionaction: ($2658) -> $2659 ()(xx: $2658); xxxx: list<$2658>.foreachstd/core/list/foreach: (xs : list<$2658>, action : ($2658) -> $2659 ()) -> $2659 ()(actionaction: ($2658) -> $2659 ()) } Nilstd/core/types/Nil: forall<a> list<a> -> (std/core/types/Unit: ())std/core/types/Unit: () // Invoke `action` for each element of a list while `action` return `Nothing` pub fun foreach-whilestd/core/list/foreach-while: forall<a,b,e> (xs : list<a>, action : (a) -> e maybe<b>) -> e maybe<b>( xsxs: list<$1404> : liststd/core/types/list: V -> V<aa: V>, actionaction: ($1404) -> $1406 maybe<$1405> : (aa: V) -> ee: E maybestd/core/types/maybe: V -> V<bb: V> )result: -> 1455 maybe<1454> : ee: E maybestd/core/types/maybe: V -> V<bb: V> match xsxs: list<$1404> Nilstd/core/types/Nil: forall<a> list<a> -> Nothingstd/core/types/Nothing: forall<a> maybe<a> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1404,xxxx: list<$1404>) -> match actionaction: ($1404) -> $1406 maybe<$1405>(xx: $1404) Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<$1404>.foreach-whilestd/core/list/foreach-while: (xs : list<$1404>, action : ($1404) -> $1406 maybe<$1405>) -> $1406 maybe<$1405>(actionaction: ($1404) -> $1406 maybe<$1405>) justjust: maybe<$1405> -> justjust: maybe<$1405> // Invoke `action` on each element of a list while `action` returns `Just` pub fun map-whilestd/core/list/map-while: forall<a,b,e> (xs : list<a>, action : (a) -> e maybe<b>) -> e list<b>( xsxs: list<$2703> : liststd/core/types/list: V -> V<aa: V>, actionaction: ($2703) -> $2705 maybe<$2704> : (aa: V) -> ee: E maybestd/core/types/maybe: V -> V<bb: V> )result: -> 2755 list<2754> : ee: E liststd/core/types/list: V -> V<bb: V> match xsxs: list<$2703> Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2703,xxxx: list<$2703>) -> match actionaction: ($2703) -> $2705 maybe<$2704>(xx: $2703) Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $2704) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2704,xxxx: list<$2703>.map-whilestd/core/list/map-while: (xs : list<$2703>, action : ($2703) -> $2705 maybe<$2704>) -> $2705 list<$2704>(actionaction: ($2703) -> $2705 maybe<$2704>)) Nothingstd/core/types/Nothing: forall<a> maybe<a> -> Nilstd/core/types/Nil: forall<a> list<a> // Invoke `action` for each element of a list, passing also the position of the element. pub fun foreach-indexedstd/core/list/foreach-indexed: forall<a,e> (xs : list<a>, action : (int, a) -> e ()) -> e ()( xsxs: list<$2765> : liststd/core/types/list: V -> V<aa: V>, actionaction: (int, $2765) -> $2766 () : (intstd/core/types/int: V,aa: V) -> ee: E (std/core/types/unit: V)std/core/types/unit: V )result: -> 2871 () : ee: E (std/core/types/unit: V)std/core/types/unit: V var ii: local-var<$2775,int> := 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
xsxs: list<$2765>.foreachstd/core/list/foreach: (xs : list<$2765>, action : ($2765) -> <local<$2775>|$2766> ()) -> <local<$2775>|$2766> () fnfn: (x : $2765) -> <local<$2775>|$2766> ()(xx: $2765) val jj: int = ii: int // don't dereference `i` inside the inject mask<local_1: H>{ actionaction: (int, $2765) -> $2766 ()(jj: int,xx: $2765) } ii: local-var<$2775,int> :=std/core/types/local-set: (v : local-var<$2775,int>, assigned : int) -> <local<$2775>|$2766> () ii: int+std/core/int/(+): (x : int, y : int) -> <local<$2775>|$2766> int
1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
// Insert a separator `sep` between all elements of a list `xs` . pub fun interspersestd/core/list/intersperse: forall<a> (xs : list<a>, sep : a) -> list<a>( xsxs: list<$2878> : liststd/core/types/list: V -> V<aa: V>, sepsep: $2878 : aa: V )result: -> total list<2937> : liststd/core/types/list: V -> V<aa: V> fun beforebefore: (ys : list<$2878>) -> list<$2878>(ysys: list<$2878>)result: -> total list<$2878> match ysys: list<$2878> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2878,yyyy: list<$2878>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(sepsep: $2878,Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2878,beforebefore: (ys : list<$2878>) -> list<$2878>(yyyy: list<$2878>))) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> match xsxs: list<$2878> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2878,xxxx: list<$2878>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2878, xxxx: list<$2878>.beforebefore: (ys : list<$2878>) -> list<$2878>) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> // Concatenate all strings in a list fun joinsepstd/core/list/joinsep: (xs : list<string>, sep : string) -> string( xsxs: list<string> : liststd/core/types/list: V -> V<stringstd/core/types/string: V>, sepsep: string : stringstd/core/types/string: V )result: -> total string : stringstd/core/types/string: V match xsxs: list<string> Nilstd/core/types/Nil: forall<a> list<a> -> ""literal: string
count= 0
Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: string,Nilstd/core/types/Nil: forall<a> list<a>) -> xx: string Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: string,Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: string,Nilstd/core/types/Nil: forall<a> list<a>)) | sepsep: string.is-emptystd/core/string/is-empty: (s : string) -> bool -> xx: string ++std/core/types/(++): (x : string, y : string) -> string yy: string _ -> xsxs: list<string>.vectorstd/core/vector/list/vector: (xs : list<string>) -> vector<string>.joinstd/core/string/vectorsep/join: (v : vector<string>, sep : string) -> string(sepsep: string
) // Concatenate all strings in a list pub fun joinstd/core/list/join: (xs : list<string>) -> string( xsxs: list<string> : liststd/core/types/list: V -> V<stringstd/core/types/string: V> )result: -> total string : stringstd/core/types/string: V match xsxs: list<string> Nilstd/core/types/Nil: forall<a> list<a> -> ""literal: string
count= 0
Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: string,Nilstd/core/types/Nil: forall<a> list<a>) -> xx: string Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: string,Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: string,Nilstd/core/types/Nil: forall<a> list<a>)) -> xx: string ++std/core/types/(++): (x : string, y : string) -> string yy: string _ -> xsxs: list<string>.vectorstd/core/vector/list/vector: (xs : list<string>) -> vector<string>.joinstd/core/string/vector/join: (v : vector<string>) -> string(
) // Concatenate all strings in a list using a specific separator pub fun joinsep/joinstd/core/list/joinsep/join: (xs : list<string>, sep : string) -> string( xsxs: list<string> : liststd/core/types/list: V -> V<stringstd/core/types/string: V>, sepsep: string : stringstd/core/types/string: V )result: -> total string : stringstd/core/types/string: V xsxs: list<string>.joinsepstd/core/list/joinsep: (xs : list<string>, sep : string) -> string(sepsep: string) // Concatenate all strings in a list in reverse order pub fun reverse-joinstd/core/list/reverse-join: (xs : list<string>) -> string( xsxs: list<string> : liststd/core/types/list: V -> V<stringstd/core/types/string: V> )result: -> total string : stringstd/core/types/string: V xsxs: list<string>.reversestd/core/list/reverse: (xs : list<string>) -> list<string>.joinstd/core/list/join: (xs : list<string>) -> string // Append `end` to each string in the list `xs` and join them all together.\ // `join-end([],end) === ""`\ // `join-end(["a","b"],"/") === "a/b/"` pub fun join-endstd/core/list/join-end: (xs : list<string>, end : string) -> string( xsxs: list<string> : liststd/core/types/list: V -> V<stringstd/core/types/string: V>, endend: string : stringstd/core/types/string: V)result: -> total string : stringstd/core/types/string: V match xsxs: list<string> Nilstd/core/types/Nil: forall<a> list<a> -> ""literal: string
count= 0
_ -> xsxs: list<string>.joinsepstd/core/list/joinsep: (xs : list<string>, sep : string) -> string(endend: string) ++std/core/types/(++): (x : string, y : string) -> string endend: string
// Concatenate all lists in a list (e.g. flatten the list). (tail-recursive) pub fun concatstd/core/list/concat: forall<a> (xss : list<list<a>>) -> list<a>( xssxss: list<list<$4361>> : liststd/core/types/list: V -> V<liststd/core/types/list: V -> V<aa: V>> )result: -> total list<4426> : liststd/core/types/list: V -> V<aa: V> fun concat-preconcat-pre: forall<a> (ys : list<a>, zss : list<list<a>>) -> list<a>( ysys: list<$4362> : liststd/core/types/list: V -> V<aa: V>, zsszss: list<list<$4362>> : liststd/core/types/list: V -> V<liststd/core/types/list: V -> V<aa: V>> )result: -> total list<4407> : liststd/core/types/list: V -> V<aa: V> match ysys: list<$4362> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $4362,yyyy: list<$4362>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $4362,concat-preconcat-pre: (ys : list<$4362>, zss : list<list<$4362>>) -> list<$4362>(yyyy: list<$4362>,zsszss: list<list<$4362>>)) Nilstd/core/types/Nil: forall<a> list<a> -> match zsszss: list<list<$4362>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(zszs: list<$4362>,zzszzs: list<list<$4362>>) -> concat-preconcat-pre: (ys : list<$4362>, zss : list<list<$4362>>) -> list<$4362>(zszs: list<$4362>,zzszzs: list<list<$4362>>) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> concat-preconcat-pre: (ys : list<$4361>, zss : list<list<$4361>>) -> list<$4361>([std/core/types/Nil: forall<a> list<a>]std/core/types/Nil: forall<a> list<a>,xssxss: list<list<$4361>>) // Concatenate the result lists from applying a function to all elements. pub fun flatmapstd/core/list/flatmap: forall<a,b,e> (xs : list<a>, f : (a) -> e list<b>) -> e list<b>( xsxs: list<$4431>: liststd/core/types/list: V -> V<aa: V>, ff: ($4431) -> $4433 list<$4432> : aa: V -> ee: E liststd/core/types/list: V -> V<bb: V> )result: -> 4488 list<4487> : ee: E liststd/core/types/list: V -> V<bb: V> fun flatmap-preflatmap-pre: (ys : list<$4432>, zs : list<$4431>) -> $4433 list<$4432>( ysys: list<$4432>, zszs: list<$4431> )result: -> $4433 list<$4432> match ysys: list<$4432> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $4432,yyyy: list<$4432>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $4432,flatmap-preflatmap-pre: (ys : list<$4432>, zs : list<$4431>) -> $4433 list<$4432>(yyyy: list<$4432>,zszs: list<$4431>)) Nilstd/core/types/Nil: forall<a> list<a> -> match zszs: list<$4431> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(zz: $4431,zzzz: list<$4431>) -> flatmap-preflatmap-pre: (ys : list<$4432>, zs : list<$4431>) -> $4433 list<$4432>(ff: ($4431) -> $4433 list<$4432>(zz: $4431),zzzz: list<$4431>) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> flatmap-preflatmap-pre: (ys : list<$4432>, zs : list<$4431>) -> $4433 list<$4432>([std/core/types/Nil: forall<a> list<a>]std/core/types/Nil: forall<a> list<a>,xsxs: list<$4431>) // Concatenate the `Just` result elements from applying a function to all elements. pub fun flatmap-maybestd/core/list/flatmap-maybe: forall<a,b,e> (xs : list<a>, f : (a) -> e maybe<b>) -> e list<b>( xsxs: list<$4498> : liststd/core/types/list: V -> V<aa: V>, ff: ($4498) -> $4500 maybe<$4499> : aa: V -> ee: E maybestd/core/types/maybe: V -> V<bb: V> )result: -> 4559 list<4558> : ee: E liststd/core/types/list: V -> V<bb: V> match xsxs: list<$4498> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $4498,xxxx: list<$4498>) -> match ff: ($4498) -> $4500 maybe<$4499>(xx: $4498) Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $4499) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $4499, xxxx: list<$4498>.flatmap-maybestd/core/list/flatmap-maybe: (xs : list<$4498>, f : ($4498) -> $4500 maybe<$4499>) -> $4500 list<$4499>(ff: ($4498) -> $4500 maybe<$4499>)) Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<$4498>.flatmap-maybestd/core/list/flatmap-maybe: (xs : list<$4498>, f : ($4498) -> $4500 maybe<$4499>) -> $4500 list<$4499>(ff: ($4498) -> $4500 maybe<$4499>) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> // Concatenate a list of `:maybe` values pub fun concat-maybestd/core/list/concat-maybe: forall<a> (xs : list<maybe<a>>) -> list<a>( xsxs: list<maybe<$4569>> : liststd/core/types/list: V -> V<maybestd/core/types/maybe: V -> V<aa: V>> )result: -> total list<4612> : liststd/core/types/list: V -> V<aa: V> match xsxs: list<maybe<$4569>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: maybe<$4569>,xxxx: list<maybe<$4569>>) -> match xx: maybe<$4569> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $4569) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $4569, xxxx: list<maybe<$4569>>.concat-maybestd/core/list/concat-maybe: (xs : list<maybe<$4569>>) -> list<$4569>) Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<maybe<$4569>>.concat-maybestd/core/list/concat-maybe: (xs : list<maybe<$4569>>) -> list<$4569> Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> // Return the last element of a list (or `Nothing` for the empty list) pub fun laststd/core/list/last: forall<a> (xs : list<a>) -> maybe<a>( xsxs: list<$4617> : liststd/core/types/list: V -> V<aa: V> )result: -> total maybe<4650> : maybestd/core/types/maybe: V -> V<aa: V> match xsxs: list<$4617> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $4617,Nilstd/core/types/Nil: forall<a> list<a>) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $4617) Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,xxxx: list<$4617>) -> laststd/core/list/last: (xs : list<$4617>) -> maybe<$4617>(xxxx: list<$4617>) Nilstd/core/types/Nil: forall<a> list<a> -> Nothingstd/core/types/Nothing: forall<a> maybe<a> // Return the list without its last element. // Return an empty list for an empty list. pub fun initstd/core/list/init: forall<a> (xs : list<a>) -> list<a>( xsxs: list<$4655> : liststd/core/types/list: V -> V<aa: V> )result: -> total list<4685> : liststd/core/types/list: V -> V<aa: V> match xsxs: list<$4655> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $4655, xxxx: list<$4655> as Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $4655,initstd/core/list/init: (xs : list<$4655>) -> list<$4655>(xxxx: list<$4655>)) _ -> Nilstd/core/types/Nil: forall<a> list<a> // Get (zero-based) element `n` of a list. Return a `:maybe` type. pub fun @index( xsxs: list<$4690> : liststd/core/types/list: V -> V<aa: V>, nn: int : intstd/core/types/int: V )result: -> total maybe<4759> : maybestd/core/types/maybe: V -> V<aa: V> match xsxs: list<$4690> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $4690,xxxx: list<$4690>) -> if nn: int>std/core/int/(>): (x : int, y : int) -> bool0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
then xxxx: list<$4690>[nn: int -std/core/int/(-): (x : int, y : int) -> int 1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
] // == @index(xx,n-1) elif nn: int==std/core/int/(==): (x : int, y : int) -> bool0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
then Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $4690) else Nothingstd/core/types/Nothing: forall<a> maybe<a> Nilstd/core/types/Nil: forall<a> list<a> -> Nothingstd/core/types/Nothing: forall<a> maybe<a> // Do all elements satisfy a predicate ? pub fun allstd/core/list/all: forall<a,e> (xs : list<a>, predicate : (a) -> e bool) -> e bool( xsxs: list<$4771> : liststd/core/types/list: V -> V<aa: V>, predicatepredicate: ($4771) -> $4772 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 4802 bool : ee: E boolstd/core/types/bool: V match xsxs: list<$4771> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $4771,xxxx: list<$4771>) -> if predicatepredicate: ($4771) -> $4772 bool(xx: $4771) then xxxx: list<$4771>.allstd/core/list/all: (xs : list<$4771>, predicate : ($4771) -> $4772 bool) -> $4772 bool(predicatepredicate: ($4771) -> $4772 bool) else Falsestd/core/types/False: bool Nilstd/core/types/Nil: forall<a> list<a> -> Truestd/core/types/True: bool // Are there any elements in a list that satisfy a predicate ? pub fun anystd/core/list/any: forall<a,e> (xs : list<a>, predicate : (a) -> e bool) -> e bool( xsxs: list<$4809> : liststd/core/types/list: V -> V<aa: V>, predicatepredicate: ($4809) -> $4810 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 4840 bool : ee: E boolstd/core/types/bool: V match xsxs: list<$4809> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $4809,xxxx: list<$4809>) -> if predicatepredicate: ($4809) -> $4810 bool(xx: $4809) then Truestd/core/types/True: bool else xxxx: list<$4809>.anystd/core/list/any: (xs : list<$4809>, predicate : ($4809) -> $4810 bool) -> $4810 bool(predicatepredicate: ($4809) -> $4810 bool) Nilstd/core/types/Nil: forall<a> list<a> -> Falsestd/core/types/False: bool // Return the sum of a list of integers pub fun sumstd/core/list/sum: (xs : list<int>) -> int( xsxs: list<int> : liststd/core/types/list: V -> V<intstd/core/types/int: V> )result: -> total int : intstd/core/types/int: V xsxs: list<int>.foldlstd/core/list/foldl: (xs : list<int>, z : int, f : (int, int) -> int) -> int( 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
, fnfn: (x : int, y : int) -> int(xx: int,yy: int) { xx: int +std/core/int/(+): (x : int, y : int) -> int yy: int }
) // Returns the smallest element of a list of integers (or `default` (=`0`) for the empty list) pub fun minimumstd/core/list/minimum: (xs : list<int>, default : ? int) -> int( xsxs: list<int> : liststd/core/types/list: V -> V<intstd/core/types/int: V>, defaultdefault: ? int : intstd/core/types/int: V = 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
)result: -> total int : intstd/core/types/int: V match xsxs: list<int> Nilstd/core/types/Nil: forall<a> list<a> -> defaultdefault: int Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: int,xxxx: list<int>) -> xxxx: list<int>.foldlstd/core/list/foldl: (xs : list<int>, z : int, f : (int, int) -> int) -> int( xx: int, minstd/core/int/min: (i : int, j : int) -> int
) // Returns the largest element of a list of integers (or `default` (=`0`) for the empty list) pub fun maximumstd/core/list/maximum: (xs : list<int>, default : ? int) -> int( xsxs: list<int> : liststd/core/types/list: V -> V<intstd/core/types/int: V>, defaultdefault: ? int : intstd/core/types/int: V = 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
)result: -> total int : intstd/core/types/int: V match xsxs: list<int> Nilstd/core/types/Nil: forall<a> list<a> -> defaultdefault: int Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: int,xxxx: list<int>) -> xxxx: list<int>.foldlstd/core/list/foldl: (xs : list<int>, z : int, f : (int, int) -> int) -> int( xx: int, maxstd/core/int/max: (i : int, j : int) -> int
) // Split a string into a list of lines pub fun linesstd/core/list/lines: (s : string) -> list<string>( ss: string : stringstd/core/types/string: V )result: -> total list<string> : liststd/core/types/list: V -> V<stringstd/core/types/string: V> ss: string.splitstd/core/string/split: (s : string, sep : string) -> list<string>("\n"literal: string
count= 1
) // Join a list of strings with newlines pub fun unlinesstd/core/list/unlines: (xs : list<string>) -> string( xsxs: list<string> : liststd/core/types/list: V -> V<stringstd/core/types/string: V> )result: -> total string : stringstd/core/types/string: V xsxs: list<string>.joinstd/core/list/joinsep/join: (xs : list<string>, sep : string) -> string("\n"literal: string
count= 1
) // Apply a function `f` to each character in a string pub fun string/mapstd/core/list/string/map: forall<e> (s : string, f : (char) -> e char) -> e string( ss: string : stringstd/core/types/string: V, ff: (char) -> $1875 char : charstd/core/types/char: V -> ee: E charstd/core/types/char: V )result: -> 1922 string : ee: E stringstd/core/types/string: V ss: string.liststd/core/string/list: (s : string) -> $1875 list<char>.mapstd/core/list/map: (xs : list<char>, f : (char) -> $1875 char) -> $1875 list<char>(ff: (char) -> $1875 char).stringstd/core/string/listchar/string: (cs : list<char>) -> $1875 string // todo: optimize