/*---------------------------------------------------------------------------
  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<586> : 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<$591> : liststd/core/types/list: V -> V<aa: V>, defaultdefault: $591 : aa: V )result: -> total 607 : astd/core/types/total: E
  match xsxs: list<$591>
    Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $591) -> xx: $591
    _       -> defaultdefault: $591

// 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<$612> : liststd/core/types/list: V -> V<aa: V> )result: -> total list<630> : liststd/core/types/list: V -> V<aa: V>
  match xsxs: list<$612>
    Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,xxxx: list<$612>) -> xxxx: list<$612>
    _          -> [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<$635> : liststd/core/types/list: V -> V<aa: V> )result: -> total bool : boolstd/core/types/bool: V
  match xsxs: list<$635>
    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: _654)result: -> total list<667>
  [std/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>xx: _654]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<_708>)result: -> total int
  fun lenlen: forall<a> (ys : list<a>, acc : int) -> int(ysys: list<_686>,accacc: int)result: -> total int
    match ysys: list<_686>
      Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,yyyy: list<_686>) -> yyyy: list<_686>.lenlen: (ys : list<_686>, 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<_708>.lenlen: (ys : list<_708>, 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) -> $1792 $1791 : intstd/core/types/int: V -> ee: E aa: V )result: -> 1846 list<1845> : ee: E liststd/core/types/list: V -> V<aa: V> if lolo: int <=std/core/int/(<=): (x : int, y : int) -> $1792 bool hihi: int then Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>( ff: (int) -> $1792 $1791(lolo: int), liststd/core/list/function/list: (lo : int, hi : int, f : (int) -> $1792 $1791) -> $1792 list<$1791>( pretend-decreasingstd/core/undiv/pretend-decreasing: (x : int) -> $1792 int(lolo: int.incstd/core/int/inc: (i : int) -> $1792 int), hihi: int, ff: (int) -> $1792 $1791 )) 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) -> $1913 $1912 : intstd/core/types/int: V -> ee: E aa: V )result: -> 1969 list<1968> : ee: E liststd/core/types/list: V -> V<aa: V> if lolo: int <=std/core/int/(<=): (x : int, y : int) -> $1913 bool hihi: int then Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>( ff: (int) -> $1913 $1912(lolo: int), liststd/core/list/stridefunction/list: (lo : int, hi : int, stride : int, f : (int) -> $1913 $1912) -> $1913 list<$1912>( pretend-decreasingstd/core/undiv/pretend-decreasing: (x : int) -> $1913 int(lolo: int +std/core/int/(+): (x : int, y : int) -> $1913 int stridestride: int), hihi: int, stridestride: int, ff: (int) -> $1913 $1912 )) 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<$718> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$718> : liststd/core/types/list: V -> V<aa: V>, (@implicit/==)?(==): ($718, $718) -> bool : (aa: V,aa: V) -> boolstd/core/types/bool: V )result: -> total bool : boolstd/core/types/bool: V match xsxs: list<$718> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $718,xxxx: list<$718>) -> match ysys: list<$718> 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: $718,yyyy: list<$718>) -> (xx: $718==?(==): ($718, $718) -> boolyy: $718) &&std/core/types/(&&): (x : bool, y : bool) -> bool (xxxx: list<$718>==std/core/list/(==): (xs : list<$718>, ys : list<$718>, @implicit/(==) : ($718, $718) -> bool) -> bool
?(==)=?(==)
yyyy: list<$718>) Nilstd/core/types/Nil: forall<a> list<a> -> match ysys: list<$718> 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<$795> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$795> : liststd/core/types/list: V -> V<aa: V>, @implicit/cmp?cmp: ($795, $795) -> order : (aa: V,aa: V) -> orderstd/core/types/order: V )result: -> total order : orderstd/core/types/order: V match xsxs: list<$795> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $795,xxxx: list<$795>) -> match ysys: list<$795> 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: $795,yyyy: list<$795>) -> match cmp?cmp: ($795, $795) -> order(xx: $795,yy: $795) Eqstd/core/types/Eq: order -> cmpstd/core/list/cmp: (xs : list<$795>, ys : list<$795>, @implicit/cmp : ($795, $795) -> order) -> order
?cmp=?cmp
(xxxx: list<$795>,yyyy: list<$795>) lglg: order -> lglg: order Nilstd/core/types/Nil: forall<a> list<a> -> match ysys: list<$795> 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<$3230> : liststd/core/types/list: V -> V<aa: V>, @implicit/show?show: ($3230) -> $3231 string : aa: V -> ee: E stringstd/core/types/string: V )result: -> 3296 string : ee: E stringstd/core/types/string: V "["literal: string
count= 1
++std/core/types/(++): (x : string, y : string) -> $3231 string xsxs: list<$3230>.mapstd/core/list/map: (xs : list<$3230>, f : ($3230) -> $3231 string) -> $3231 list<string>(show?show: ($3230) -> $3231 string).joinstd/core/list/joinsep/join: (xs : list<string>, sep : string) -> $3231 string(","literal: string
count= 1
) ++std/core/types/(++): (x : string, y : string) -> $3231 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<$3313> : liststd/core/types/list: V -> V<aa: V>, show-elemshow-elem: ($3313) -> $3314 string : (aa: V) -> ee: E stringstd/core/types/string: V )result: -> 3335 string : ee: E stringstd/core/types/string: V showstd/core/list/show: (xs : list<$3313>, @implicit/show : ($3313) -> $3314 string) -> $3314 string(xsxs: list<$3313>,@implicit/show=show-elemshow-elem: ($3313) -> $3314 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<$3342> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$3343> : liststd/core/types/list: V -> V<bb: V> )result: -> total list<(3404, 3405)> : liststd/core/types/list: V -> V<(std/core/types/tuple2: (V, V) -> Vaa: V,bb: V)> match xsxs: list<$3342> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $3342,xxxx: list<$3342>) -> match ysys: list<$3343> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $3343,yyyy: list<$3343>) -> 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: $3342,yy: $3343)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b),zipstd/core/list/zip: (xs : list<$3342>, ys : list<$3343>) -> list<($3342, $3343)>(xxxx: list<$3342>,yyyy: list<$3343>)) 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<$3413> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$3414> :liststd/core/types/list: V -> V<bb: V>, ff: ($3413, $3414) -> $3416 $3415 : (aa: V,bb: V) -> ee: E cc: V )result: -> 3483 list<3482> : ee: E liststd/core/types/list: V -> V<cc: V> match xsxs: list<$3413> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $3413,xxxx: list<$3413>) -> match ysys: list<$3414> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $3414,yyyy: list<$3414>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: ($3413, $3414) -> $3416 $3415(xx: $3413,yy: $3414),zipwithstd/core/list/zipwith: (xs : list<$3413>, ys : list<$3414>, f : ($3413, $3414) -> $3416 $3415) -> $3416 list<$3415>(xxxx: list<$3413>,yyyy: list<$3414>,ff: ($3413, $3414) -> $3416 $3415)) 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<$3496> : liststd/core/types/list: V -> V<aa: V>, ys0ys0: list<$3497> :liststd/core/types/list: V -> V<bb: V>, ff: (int, $3496, $3497) -> $3499 $3498 : (intstd/core/types/int: V,aa: V,bb: V) -> ee: E cc: V )result: -> 3576 list<3575> : ee: E liststd/core/types/list: V -> V<cc: V> fun zipwith-iterzipwith-iter: (i : int, xs : list<$3496>, ys : list<$3497>) -> $3499 list<$3498>( ii: int, xsxs: list<$3496>, ysys: list<$3497> )result: -> $3499 list<$3498> match xsxs: list<$3496> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $3496,xxxx: list<$3496>) -> match ysys: list<$3497> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $3497,yyyy: list<$3497>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (int, $3496, $3497) -> $3499 $3498(ii: int,xx: $3496,yy: $3497),zipwith-iterzipwith-iter: (i : int, xs : list<$3496>, ys : list<$3497>) -> $3499 list<$3498>(ii: int+std/core/int/(+): (x : int, y : int) -> $3499 int1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
,xxxx: list<$3496>,yyyy: list<$3497>)) 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<$3496>, ys : list<$3497>) -> $3499 list<$3498>(0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
,xs0xs0: list<$3496>,ys0ys0: list<$3497>
) // 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<($3589, $3590)> : liststd/core/types/list: V -> V<(std/core/types/tuple2: (V, V) -> Vaa: V,bb: V)> )result: -> total (list<3782>, list<3783>) : (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<(_3607, _3608)>, acc1acc1: cctx<_3649,list<_3607>>, acc2acc2: cctx<_3689,list<_3608>> )result: -> total (_3649, _3689) match ysys: list<(_3607, _3608)> 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: _3607,yy: _3608)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b),xxxx: list<(_3607, _3608)>) -> iteriter: (ys : list<(_3607, _3608)>, acc1 : cctx<_3649,list<_3607>>, acc2 : cctx<_3689,list<_3608>>) -> (_3649, _3689)(xxxx: list<(_3607, _3608)>,acc1acc1: cctx<_3649,list<_3607>> ++std/core/types/cctx/(++): (c1 : cctx<_3649,list<_3607>>, c2 : cctx<list<_3607>,list<_3607>>) -> cctx<_3649,list<_3607>> ctxctx: cctx<list<_3607>,list<_3607>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: _3607,_hole: list<_3607>),acc2acc2: cctx<_3689,list<_3608>> ++std/core/types/cctx/(++): (c1 : cctx<_3689,list<_3608>>, c2 : cctx<list<_3608>,list<_3608>>) -> cctx<_3689,list<_3608>> ctxctx: cctx<list<_3608>,list<_3608>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: _3608,_hole: list<_3608>)) Nilstd/core/types/Nil: forall<a> list<a> -> (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)acc1acc1: cctx<_3649,list<_3607>> ++.std/core/types/cctx/(++.): (c : cctx<_3649,list<_3607>>, x : list<_3607>) -> _3649 Nilstd/core/types/Nil: forall<a> list<a>,acc2acc2: cctx<_3689,list<_3608>> ++.std/core/types/cctx/(++.): (c : cctx<_3689,list<_3608>>, x : list<_3608>) -> _3689 Nilstd/core/types/Nil: forall<a> list<a>)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) iteriter: (ys : list<($3589, $3590)>, acc1 : cctx<list<$3589>,list<$3589>>, acc2 : cctx<list<$3590>,list<$3590>>) -> (list<$3589>, list<$3590>)(xsxs: list<($3589, $3590)>,ctxctx: ctx<list<$3589>> _hole: list<$3589>,ctxctx: ctx<list<$3590>> _hole: list<$3590>) // 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<($3791, $3792, $3793)> : liststd/core/types/list: V -> V<(std/core/types/tuple3: (V, V, V) -> Vaa: V,bb: V,cc: V)>)result: -> total (list<4067>, list<4068>, list<4069>) : (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<(_3813, _3814, _3815)>, acc1acc1: cctx<_3856,list<_3813>>, acc2acc2: cctx<_3896,list<_3814>>, acc3acc3: cctx<_3936,list<_3815>> )result: -> total (_3856, _3896, _3936) match ysys: list<(_3813, _3814, _3815)> 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: _3813,yy: _3814,zz: _3815)std/core/types/Tuple3: forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c),xxxx: list<(_3813, _3814, _3815)>) -> iteriter: (ys : list<(_3813, _3814, _3815)>, acc1 : cctx<_3856,list<_3813>>, acc2 : cctx<_3896,list<_3814>>, acc3 : cctx<_3936,list<_3815>>) -> (_3856, _3896, _3936)(xxxx: list<(_3813, _3814, _3815)>,acc1acc1: cctx<_3856,list<_3813>> ++std/core/types/cctx/(++): (c1 : cctx<_3856,list<_3813>>, c2 : cctx<list<_3813>,list<_3813>>) -> cctx<_3856,list<_3813>> ctxctx: cctx<list<_3813>,list<_3813>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: _3813,_hole: list<_3813>),acc2acc2: cctx<_3896,list<_3814>> ++std/core/types/cctx/(++): (c1 : cctx<_3896,list<_3814>>, c2 : cctx<list<_3814>,list<_3814>>) -> cctx<_3896,list<_3814>> ctxctx: cctx<list<_3814>,list<_3814>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: _3814,_hole: list<_3814>),acc3acc3: cctx<_3936,list<_3815>> ++std/core/types/cctx/(++): (c1 : cctx<_3936,list<_3815>>, c2 : cctx<list<_3815>,list<_3815>>) -> cctx<_3936,list<_3815>> ctxctx: cctx<list<_3815>,list<_3815>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(zz: _3815,_hole: list<_3815>)) 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<_3856,list<_3813>> ++.std/core/types/cctx/(++.): (c : cctx<_3856,list<_3813>>, x : list<_3813>) -> _3856 Nilstd/core/types/Nil: forall<a> list<a>,acc2acc2: cctx<_3896,list<_3814>> ++.std/core/types/cctx/(++.): (c : cctx<_3896,list<_3814>>, x : list<_3814>) -> _3896 Nilstd/core/types/Nil: forall<a> list<a>,acc3acc3: cctx<_3936,list<_3815>> ++.std/core/types/cctx/(++.): (c : cctx<_3936,list<_3815>>, x : list<_3815>) -> _3936 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<($3791, $3792, $3793)>, acc1 : cctx<list<$3791>,list<$3791>>, acc2 : cctx<list<$3792>,list<$3792>>, acc3 : cctx<list<$3793>,list<$3793>>) -> (list<$3791>, list<$3792>, list<$3793>)(xsxs: list<($3791, $3792, $3793)>,ctxctx: ctx<list<$3791>> _hole: list<$3791>,ctxctx: ctx<list<$3792>> _hole: list<$3792>,ctxctx: ctx<list<$3793>> _hole: list<$3793>) // 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<($4080, $4081, $4082, $4083)> : 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<4439>, list<4440>, list<4441>, list<4442>) : (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<(_4106, _4107, _4108, _4109)>, acc1acc1: cctx<_4150,list<_4106>>, acc2acc2: cctx<_4190,list<_4107>>, acc3acc3: cctx<_4230,list<_4108>>, acc4acc4: cctx<_4270,list<_4109>> )result: -> total (_4150, _4190, _4230, _4270) match ysys: list<(_4106, _4107, _4108, _4109)> 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: _4106,yy: _4107,zz: _4108,ww: _4109)std/core/types/Tuple4: forall<a,b,c,d> (fst : a, snd : b, thd : c, field4 : d) -> (a, b, c, d),xxxx: list<(_4106, _4107, _4108, _4109)>) -> iteriter: (ys : list<(_4106, _4107, _4108, _4109)>, acc1 : cctx<_4150,list<_4106>>, acc2 : cctx<_4190,list<_4107>>, acc3 : cctx<_4230,list<_4108>>, acc4 : cctx<_4270,list<_4109>>) -> (_4150, _4190, _4230, _4270)(xxxx: list<(_4106, _4107, _4108, _4109)>,acc1acc1: cctx<_4150,list<_4106>> ++std/core/types/cctx/(++): (c1 : cctx<_4150,list<_4106>>, c2 : cctx<list<_4106>,list<_4106>>) -> cctx<_4150,list<_4106>> ctxctx: cctx<list<_4106>,list<_4106>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: _4106,_hole: list<_4106>),acc2acc2: cctx<_4190,list<_4107>> ++std/core/types/cctx/(++): (c1 : cctx<_4190,list<_4107>>, c2 : cctx<list<_4107>,list<_4107>>) -> cctx<_4190,list<_4107>> ctxctx: cctx<list<_4107>,list<_4107>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: _4107,_hole: list<_4107>),acc3acc3: cctx<_4230,list<_4108>> ++std/core/types/cctx/(++): (c1 : cctx<_4230,list<_4108>>, c2 : cctx<list<_4108>,list<_4108>>) -> cctx<_4230,list<_4108>> ctxctx: cctx<list<_4108>,list<_4108>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(zz: _4108,_hole: list<_4108>),acc4acc4: cctx<_4270,list<_4109>> ++std/core/types/cctx/(++): (c1 : cctx<_4270,list<_4109>>, c2 : cctx<list<_4109>,list<_4109>>) -> cctx<_4270,list<_4109>> ctxctx: cctx<list<_4109>,list<_4109>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ww: _4109,_hole: list<_4109>)) 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<_4150,list<_4106>> ++.std/core/types/cctx/(++.): (c : cctx<_4150,list<_4106>>, x : list<_4106>) -> _4150 Nilstd/core/types/Nil: forall<a> list<a>,acc2acc2: cctx<_4190,list<_4107>> ++.std/core/types/cctx/(++.): (c : cctx<_4190,list<_4107>>, x : list<_4107>) -> _4190 Nilstd/core/types/Nil: forall<a> list<a>,acc3acc3: cctx<_4230,list<_4108>> ++.std/core/types/cctx/(++.): (c : cctx<_4230,list<_4108>>, x : list<_4108>) -> _4230 Nilstd/core/types/Nil: forall<a> list<a>,acc4acc4: cctx<_4270,list<_4109>> ++.std/core/types/cctx/(++.): (c : cctx<_4270,list<_4109>>, x : list<_4109>) -> _4270 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<($4080, $4081, $4082, $4083)>, acc1 : cctx<list<$4080>,list<$4080>>, acc2 : cctx<list<$4081>,list<$4081>>, acc3 : cctx<list<$4082>,list<$4082>>, acc4 : cctx<list<$4083>,list<$4083>>) -> (list<$4080>, list<$4081>, list<$4082>, list<$4083>)(xsxs: list<($4080, $4081, $4082, $4083)>,ctxctx: ctx<list<$4080>> _hole: list<$4080>,ctxctx: ctx<list<$4081>> _hole: list<$4081>,ctxctx: ctx<list<$4082>> _hole: list<$4082>,ctxctx: ctx<list<$4083>> _hole: list<$4083>) // 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<$865> : liststd/core/types/list: V -> V<aa: V>, nn: int : intstd/core/types/int: V )result: -> total list<906> : liststd/core/types/list: V -> V<aa: V> match xsxs: list<$865> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $865,xxxx: list<$865>) | 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: $865, takestd/core/list/take: (xs : list<$865>, n : int) -> list<$865>(xxxx: list<$865>, 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<$911> : liststd/core/types/list: V -> V<aa: V>, nn: int : intstd/core/types/int: V )result: -> total list<943> : liststd/core/types/list: V -> V<aa: V> match xsxs: list<$911> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,xxxx: list<$911>) | nn: int >std/core/int/(>): (x : int, y : int) -> bool 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
-> dropstd/core/list/drop: (xs : list<$911>, n : int) -> list<$911>(xxxx: list<$911>, nn: int -std/core/int/(-): (x : int, y : int) -> int 1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
) _ -> xsxs: list<$911>
// 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<$2019> : liststd/core/types/list: V -> V<aa: V>, ff: ($2019) -> $2021 $2020 : aa: V -> ee: E bb: V)result: -> 2072 list<2071> : ee: E liststd/core/types/list: V -> V<bb: V> match xsxs: list<$2019> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2019,xxxx: list<$2019>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: ($2019) -> $2021 $2020(xx: $2019), xxxx: list<$2019>.mapstd/core/list/map: (xs : list<$2019>, f : ($2019) -> $2021 $2020) -> $2021 list<$2020>(ff: ($2019) -> $2021 $2020)) 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<$2121> : liststd/core/types/list: V -> V<aa: V>, ff: (idx : int, value : $2121) -> $2123 $2122 : (idx : intstd/core/types/int: V, value : aa: V) -> ee: E bb: V)result: -> 2179 list<2178> : ee: E liststd/core/types/list: V -> V<bb: V> fun map-idxmap-idx: (ys : list<$2121>, i : int) -> $2123 list<$2122>(ysys: list<$2121>,ii: int)result: -> $2123 list<$2122> match ysys: list<$2121> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2121,yyyy: list<$2121>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (idx : int, value : $2121) -> $2123 $2122(ii: int,yy: $2121), map-idxmap-idx: (ys : list<$2121>, i : int) -> $2123 list<$2122>(yyyy: list<$2121>,ii: int+std/core/int/(+): (x : int, y : int) -> $2123 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<$2121>, i : int) -> $2123 list<$2122>(xsxs: list<$2121>,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<$2189> : liststd/core/types/list: V -> V<aa: V>, ff: (value : $2189, rest : list<$2189>) -> $2191 $2190 : (value : aa: V, rest : liststd/core/types/list: V -> V<aa: V>) -> ee: E bb: V)result: -> 2238 list<2237> : ee: E liststd/core/types/list: V -> V<bb: V> fun mappeekmappeek: (ys : list<$2189>) -> $2191 list<$2190>(ysys: list<$2189>)result: -> $2191 list<$2190> match ysys: list<$2189> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2189,yyyy: list<$2189>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (value : $2189, rest : list<$2189>) -> $2191 $2190(yy: $2189,yyyy: list<$2189>), yyyy: list<$2189>.mappeekmappeek: (ys : list<$2189>) -> $2191 list<$2190>) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> mappeekmappeek: (ys : list<$2189>) -> $2191 list<$2190>(xsxs: list<$2189>) // 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<$2248> : liststd/core/types/list: V -> V<aa: V>, ff: (idx : int, value : $2248, rest : list<$2248>) -> $2250 $2249 : (idx : intstd/core/types/int: V, value : aa: V, rest : liststd/core/types/list: V -> V<aa: V> ) -> ee: E bb: V)result: -> 2307 list<2306> : ee: E liststd/core/types/list: V -> V<bb: V> fun mapidxmapidx: (ys : list<$2248>, i : int) -> $2250 list<$2249>(ysys: list<$2248>,ii: int)result: -> $2250 list<$2249> match ysys: list<$2248> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2248,yyyy: list<$2248>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (idx : int, value : $2248, rest : list<$2248>) -> $2250 $2249(ii: int,yy: $2248,yyyy: list<$2248>), mapidxmapidx: (ys : list<$2248>, i : int) -> $2250 list<$2249>(yyyy: list<$2248>,ii: int+std/core/int/(+): (x : int, y : int) -> $2250 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<$2248>, i : int) -> $2250 list<$2249>(xsxs: list<$2248>,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<$1003> : liststd/core/types/list: V -> V<aa: V>)result: -> total list<1020> : liststd/core/types/list: V -> V<aa: V> reverse-appendstd/core/list/reverse-append: (xs : list<$1003>, tl : list<$1003>) -> list<$1003>( xsxs: list<$1003>, 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<$948> : liststd/core/types/list: V -> V<aa: V>, tltl: list<$948> : liststd/core/types/list: V -> V<aa: V> )result: -> total list<998> : liststd/core/types/list: V -> V<aa: V> fun reverse-accreverse-acc: forall<a> (acc : list<a>, ys : list<a>) -> list<a>(accacc: list<$949> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$949> : liststd/core/types/list: V -> V<aa: V> )result: -> total list<979> : liststd/core/types/list: V -> V<aa: V> match ysys: list<$949> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $949,xxxx: list<$949>) -> reverse-accreverse-acc: (acc : list<$949>, ys : list<$949>) -> list<$949>(Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $949,accacc: list<$949>),xxxx: list<$949>) _ -> accacc: list<$949> reverse-accreverse-acc: (acc : list<$948>, ys : list<$948>) -> list<$948>(tltl: list<$948>,xsxs: list<$948>) // Append two lists. pub fun (++)std/core/list/(++): forall<a> (xs : list<a>, ys : list<a>) -> list<a>(xsxs: list<$1061> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$1061> : liststd/core/types/list: V -> V<aa: V> )result: -> total list<1076> : liststd/core/types/list: V -> V<aa: V> appendstd/core/list/append: (xs : list<$1061>, ys : list<$1061>) -> list<$1061>(xsxs: list<$1061>,ysys: list<$1061>) // Append two lists. pub fun appendstd/core/list/append: forall<a> (xs : list<a>, ys : list<a>) -> list<a>(xsxs: list<$1025> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$1025> : liststd/core/types/list: V -> V<aa: V> )result: -> total list<1056> : liststd/core/types/list: V -> V<aa: V> match xsxs: list<$1025> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1025,xxxx: list<$1025>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1025,appendstd/core/list/append: (xs : list<$1025>, ys : list<$1025>) -> list<$1025>(xxxx: list<$1025>,ysys: list<$1025>)) Nilstd/core/types/Nil: forall<a> list<a> -> ysys: list<$1025> // 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<$1133> : liststd/core/types/list: V -> V<aa: V>, zz: $1134 : bb: V, ff: ($1133, $1134) -> $1135 $1134 : (aa: V, bb: V) -> ee: E bb: V)result: -> 1173 1172 : ee: E bb: V xsxs: list<$1133>.reversestd/core/list/reverse: (xs : list<$1133>) -> $1135 list<$1133>.foldlstd/core/list/foldl: (xs : list<$1133>, z : $1134, f : ($1134, $1133) -> $1135 $1134) -> $1135 $1134(zz: $1134) fnfn: (x : $1134, y : $1133) -> $1135 $1134(xx: $1134,yy: $1133) ff: ($1133, $1134) -> $1135 $1134(yy: $1133,xx: $1134) // 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<$1081> : liststd/core/types/list: V -> V<aa: V>, zz: $1082 : bb: V, ff: ($1082, $1081) -> $1083 $1082 : (bb: V, aa: V) -> ee: E bb: V)result: -> 1123 1122 : ee: E bb: V match xsxs: list<$1081> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1081,xxxx: list<$1081>) -> foldlstd/core/list/foldl: (xs : list<$1081>, z : $1082, f : ($1082, $1081) -> $1083 $1082) -> $1083 $1082(xxxx: list<$1081>,ff: ($1082, $1081) -> $1083 $1082(zz: $1082,xx: $1081),ff: ($1082, $1081) -> $1083 $1082) Nilstd/core/types/Nil: forall<a> list<a> -> zz: $1082 pub fun foldl1std/core/list/foldl1: forall<a,e> (xs : list<a>, f : (a, a) -> <exn|e> a) -> <exn|e> a(xsxs: list<$1183> : liststd/core/types/list: V -> V<aa: V>, ff: ($1183, $1183) -> <exn|$1184> $1183 : (aa: V,aa: V) -> <exnstd/core/exn/exn: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V)result: -> <exn|1226> 1225 : <exnstd/core/exn/exn: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V match xsxs: list<$1183> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1183,xxxx: list<$1183>) -> xxxx: list<$1183>.foldlstd/core/list/foldl: (xs : list<$1183>, z : $1183, f : ($1183, $1183) -> <exn|$1184> $1183) -> <exn|$1184> $1183(xx: $1183,ff: ($1183, $1183) -> <exn|$1184> $1183) Nilstd/core/types/Nil: forall<a> list<a> -> throwstd/core/exn/throw: (message : string, info : ? exception-info) -> <exn|$1184> $1183("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<$1233> : liststd/core/types/list: V -> V<aa: V>, ff: ($1233, $1233) -> <exn|$1234> $1233 : (aa: V,aa: V) -> <exnstd/core/exn/exn: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V)result: -> <exn|1260> 1259 : <exnstd/core/exn/exn: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V xsxs: list<$1233>.reversestd/core/list/reverse: (xs : list<$1233>) -> <exn|$1234> list<$1233>.foldl1std/core/list/foldl1: (xs : list<$1233>, f : ($1233, $1233) -> <exn|$1234> $1233) -> <exn|$1234> $1233(ff: ($1233, $1233) -> <exn|$1234> $1233) // Create a list of `n` repeated elements `x` pub fun replicatestd/core/list/replicate: forall<a> (x : a, n : int) -> list<a>( xx: $2317 : aa: V, nn: int : intstd/core/types/int: V )result: -> total list<2360> : 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: $2317, replicatestd/core/list/replicate: (x : $2317, n : int) -> list<$2317>(xx: $2317,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<$1267> : liststd/core/types/list: V -> V<aa: V>, nn: int : intstd/core/types/int: V )result: -> total (list<1299>, list<1299>) : (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<$1267>.takestd/core/list/take: (xs : list<$1267>, n : int) -> list<$1267>(nn: int), xsxs: list<$1267>.dropstd/core/list/drop: (xs : list<$1267>, n : int) -> list<$1267>(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<$4456> : liststd/core/types/list: V -> V<aa: V>, predicatepredicate: ($4456) -> $4457 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 4538 (list<4537>, list<4537>) : 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<$4456>, acc : list<$4456>) -> $4457 (list<$4456>, list<$4456>)( ysys: list<$4456>, accacc: list<$4456>)result: -> $4457 (list<$4456>, list<$4456>) match ysys: list<$4456> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $4456,yyyy: list<$4456>) -> if yy: $4456.predicatepredicate: ($4456) -> $4457 bool then yyyy: list<$4456>.span-accspan-acc: (ys : list<$4456>, acc : list<$4456>) -> $4457 (list<$4456>, list<$4456>)(Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $4456,accacc: list<$4456>)) else (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)accacc: list<$4456>.reversestd/core/list/reverse: (xs : list<$4456>) -> $4457 list<$4456>,ysys: list<$4456>)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<$4456>.reversestd/core/list/reverse: (xs : list<$4456>) -> $4457 list<$4456>, ysys: list<$4456>)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) xsxs: list<$4456>.span-accspan-acc: (ys : list<$4456>, acc : list<$4456>) -> $4457 (list<$4456>, list<$4456>)( [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<$4545> : liststd/core/types/list: V -> V<aa: V>, predicatepredicate: ($4545) -> $4546 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 4592 list<4591> : ee: E liststd/core/types/list: V -> V<aa: V> match xsxs: list<$4545> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $4545,xxxx: list<$4545>) -> if xx: $4545.predicatepredicate: ($4545) -> $4546 bool then Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $4545, xxxx: list<$4545>.take-whilestd/core/list/take-while: (xs : list<$4545>, predicate : ($4545) -> $4546 bool) -> $4546 list<$4545>(predicatepredicate: ($4545) -> $4546 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<$1304> : liststd/core/types/list: V -> V<aa: V>, predicatepredicate: ($1304) -> $1305 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 1342 list<1341> : ee: E liststd/core/types/list: V -> V<aa: V> match xsxs: list<$1304> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1304,xxxx: list<$1304>) -> if xx: $1304.predicatepredicate: ($1304) -> $1305 bool then xxxx: list<$1304>.drop-whilestd/core/list/drop-while: (xs : list<$1304>, predicate : ($1304) -> $1305 bool) -> $1305 list<$1304>(predicatepredicate: ($1304) -> $1305 bool) else xsxs: list<$1304> 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<$1349> : liststd/core/types/list: V -> V<aa: V>, predpred: ($1349) -> $1350 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 1402 list<1401> : ee: E liststd/core/types/list: V -> V<aa: V> match xsxs: list<$1349> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1349,xxxx: list<$1349>) -> if predpred: ($1349) -> $1350 bool(xx: $1349) then Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1349,xxxx: list<$1349>.filterstd/core/list/filter: (xs : list<$1349>, pred : ($1349) -> $1350 bool) -> $1350 list<$1349>(predpred: ($1349) -> $1350 bool)) else xxxx: list<$1349>.filterstd/core/list/filter: (xs : list<$1349>, pred : ($1349) -> $1350 bool) -> $1350 list<$1349>(predpred: ($1349) -> $1350 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<$2365> : liststd/core/types/list: V -> V<aa: V>, predpred: ($2365) -> $2366 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 2399 list<2398> : ee: E liststd/core/types/list: V -> V<aa: V> xsxs: list<$2365>.filterstd/core/list/filter: (xs : list<$2365>, pred : ($2365) -> $2366 bool) -> $2366 list<$2365>( fnfn: (x : $2365) -> $2366 bool(xx: $2365) !std/core/types/bool/(!): (b : bool) -> $2366 boolpredpred: ($2365) -> $2366 bool(xx: $2365) ) // 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<$2555> : liststd/core/types/list: V -> V<aa: V>, ^predpred: ($2555) -> $2556 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 2592 (list<2591>, list<2591>) : 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<$2555>, pred : ($2555) -> $2556 bool, acc1 : ctx<list<$2555>>, acc2 : ctx<list<$2555>>) -> $2556 (list<$2555>, list<$2555>)(xsxs: list<$2555>, predpred: ($2555) -> $2556 bool, ctxctx: ctx<list<$2555>> _hole: list<$2555>, ctxctx: ctx<list<$2555>> _hole: list<$2555>) 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<$2406> : liststd/core/types/list: V -> V<aa: V>, ^predpred: ($2406) -> $2407 bool : aa: V -> ee: E boolstd/core/types/bool: V, acc1acc1: ctx<list<$2406>> : ctxstd/core/types/ctx: V -> V<liststd/core/types/list: V -> V<aa: V>>, acc2acc2: ctx<list<$2406>> : ctxstd/core/types/ctx: V -> V<liststd/core/types/list: V -> V<aa: V>>)result: -> 2548 (list<2547>, list<2547>): 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<$2406> Nilstd/core/types/Nil: forall<a> list<a> -> (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)acc1acc1: ctx<list<$2406>> ++.std/core/types/cctx/(++.): (c : cctx<list<$2406>,list<$2406>>, x : list<$2406>) -> $2407 list<$2406> Nilstd/core/types/Nil: forall<a> list<a>, acc2acc2: ctx<list<$2406>> ++.std/core/types/cctx/(++.): (c : cctx<list<$2406>,list<$2406>>, x : list<$2406>) -> $2407 list<$2406> 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: $2406,xxxx: list<$2406>) -> if predpred: ($2406) -> $2407 bool(xx: $2406) then partition-accstd/core/list/partition-acc: (xs : list<$2406>, pred : ($2406) -> $2407 bool, acc1 : ctx<list<$2406>>, acc2 : ctx<list<$2406>>) -> $2407 (list<$2406>, list<$2406>)(xxxx: list<$2406>,predpred: ($2406) -> $2407 bool,acc1acc1: ctx<list<$2406>> ++std/core/types/cctx/(++): (c1 : cctx<list<$2406>,list<$2406>>, c2 : cctx<list<$2406>,list<$2406>>) -> $2407 cctx<list<$2406>,list<$2406>> ctxctx: cctx<list<$2406>,list<$2406>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2406,_hole: list<$2406>),acc2acc2: ctx<list<$2406>>) else partition-accstd/core/list/partition-acc: (xs : list<$2406>, pred : ($2406) -> $2407 bool, acc1 : ctx<list<$2406>>, acc2 : ctx<list<$2406>>) -> $2407 (list<$2406>, list<$2406>)(xxxx: list<$2406>,predpred: ($2406) -> $2407 bool,acc1acc1: ctx<list<$2406>>,acc2acc2: ctx<list<$2406>> ++std/core/types/cctx/(++): (c1 : cctx<list<$2406>,list<$2406>>, c2 : cctx<list<$2406>,list<$2406>>) -> $2407 cctx<list<$2406>,list<$2406>> ctxctx: cctx<list<$2406>,list<$2406>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2406,_hole: list<$2406>)) // 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<$1409> : liststd/core/types/list: V -> V<aa: V>, predpred: ($1409) -> $1411 maybe<$1410> : aa: V -> ee: E maybestd/core/types/maybe: V -> V<bb: V> )result: -> 1478 list<1477> : ee: E liststd/core/types/list: V -> V<bb: V> match xsxs: list<$1409> 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: $1409,xxxx: list<$1409>) -> match predpred: ($1409) -> $1411 maybe<$1410>(xx: $1409) Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<$1409>.filter-mapstd/core/list/filter-map: (xs : list<$1409>, pred : ($1409) -> $1411 maybe<$1410>) -> $1411 list<$1410>(predpred: ($1409) -> $1411 maybe<$1410>) Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $1410) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $1410,xxxx: list<$1409>.filter-mapstd/core/list/filter-map: (xs : list<$1409>, pred : ($1409) -> $1411 maybe<$1410>) -> $1411 list<$1410>(predpred: ($1409) -> $1411 maybe<$1410>)) // 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<$1562> : liststd/core/types/list: V -> V<aa: V>, predpred: ($1562) -> $1563 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 1611 maybe<1610> : ee: E maybestd/core/types/maybe: V -> V<aa: V> xsxs: list<$1562>.foreach-whilestd/core/list/foreach-while: (xs : list<$1562>, action : ($1562) -> $1563 maybe<$1562>) -> $1563 maybe<$1562> fnfn: (x : $1562) -> $1563 maybe<$1562>(xx: $1562) if predpred: ($1562) -> $1563 bool(xx: $1562) then Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $1562) 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<$1618> : liststd/core/types/list: V -> V<aa: V>, predpred: ($1618) -> $1620 maybe<$1619> : aa: V -> ee: E maybestd/core/types/maybe: V -> V<bb: V> )result: -> 1658 maybe<1657> : ee: E maybestd/core/types/maybe: V -> V<bb: V> xsxs: list<$1618>.foreach-whilestd/core/list/foreach-while: (xs : list<$1618>, action : ($1618) -> $1620 maybe<$1619>) -> $1620 maybe<$1619>(predpred: ($1618) -> $1620 maybe<$1619>) // 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<($2599, $2600)> : liststd/core/types/list: V -> V<(std/core/types/tuple2: (V, V) -> Vaa: V,bb: V)>, predpred: ($2599) -> $2601 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 2724 maybe<2723> : ee: E maybestd/core/types/maybe: V -> V<bb: V> xsxs: list<($2599, $2600)>.foreach-whilestd/core/list/foreach-while: (xs : list<($2599, $2600)>, action : (($2599, $2600)) -> $2601 maybe<$2600>) -> $2601 maybe<$2600> fnfn: (kv : ($2599, $2600)) -> $2601 maybe<$2600>(kvkv: ($2599, $2600)) if predpred: ($2599) -> $2601 bool(kvkv: ($2599, $2600).fststd/core/types/tuple2/fst: (tuple2 : ($2599, $2600)) -> $2601 $2599) then Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(kvkv: ($2599, $2600).sndstd/core/types/tuple2/snd: (tuple2 : ($2599, $2600)) -> $2601 $2600) 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<$1668> : maybestd/core/types/maybe: V -> V<aa: V> )result: -> total list<1696> : liststd/core/types/list: V -> V<aa: V> match mm: maybe<$1668> 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: $1668) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1668,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<$2734> : liststd/core/types/list: V -> V<aa: V>, predpred: ($2734) -> $2735 bool : aa: V -> ee: E boolstd/core/types/bool: V, idxidx: int : intstd/core/types/int: V )result: -> 2775 int : ee: E intstd/core/types/int: V match xsxs: list<$2734> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2734,xxxx: list<$2734>) -> if predpred: ($2734) -> $2735 bool(xx: $2734) then idxidx: int else index-of-accstd/core/list/index-of-acc: (xs : list<$2734>, pred : ($2734) -> $2735 bool, idx : int) -> $2735 int(xxxx: list<$2734>,predpred: ($2734) -> $2735 bool,idxidx: int+std/core/int/(+): (x : int, y : int) -> $2735 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<$2782> : liststd/core/types/list: V -> V<aa: V>, predpred: ($2782) -> $2783 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 2804 int : ee: E intstd/core/types/int: V index-of-accstd/core/list/index-of-acc: (xs : list<$2782>, pred : ($2782) -> $2783 bool, idx : int) -> $2783 int( xsxs: list<$2782>, predpred: ($2782) -> $2783 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<$2811> : liststd/core/types/list: V -> V<aa: V>, actionaction: ($2811) -> $2812 () : (aa: V) -> ee: E (std/core/types/unit: V)std/core/types/unit: V )result: -> 2850 () : ee: E (std/core/types/unit: V)std/core/types/unit: V match xsxs: list<$2811> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2811,xxxx: list<$2811>) -> { actionaction: ($2811) -> $2812 ()(xx: $2811); xxxx: list<$2811>.foreachstd/core/list/foreach: (xs : list<$2811>, action : ($2811) -> $2812 ()) -> $2812 ()(actionaction: ($2811) -> $2812 ()) } 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<$1488> : liststd/core/types/list: V -> V<aa: V>, actionaction: ($1488) -> $1490 maybe<$1489> : (aa: V) -> ee: E maybestd/core/types/maybe: V -> V<bb: V> )result: -> 1546 maybe<1545> : ee: E maybestd/core/types/maybe: V -> V<bb: V> match xsxs: list<$1488> 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: $1488,xxxx: list<$1488>) -> match actionaction: ($1488) -> $1490 maybe<$1489>(xx: $1488) Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<$1488>.foreach-whilestd/core/list/foreach-while: (xs : list<$1488>, action : ($1488) -> $1490 maybe<$1489>) -> $1490 maybe<$1489>(actionaction: ($1488) -> $1490 maybe<$1489>) justjust: maybe<$1489> -> justjust: maybe<$1489> // 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<$2861> : liststd/core/types/list: V -> V<aa: V>, actionaction: ($2861) -> $2863 maybe<$2862> : (aa: V) -> ee: E maybestd/core/types/maybe: V -> V<bb: V> )result: -> 2921 list<2920> : ee: E liststd/core/types/list: V -> V<bb: V> match xsxs: list<$2861> 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: $2861,xxxx: list<$2861>) -> match actionaction: ($2861) -> $2863 maybe<$2862>(xx: $2861) Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $2862) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2862,xxxx: list<$2861>.map-whilestd/core/list/map-while: (xs : list<$2861>, action : ($2861) -> $2863 maybe<$2862>) -> $2863 list<$2862>(actionaction: ($2861) -> $2863 maybe<$2862>)) 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<$2931> : liststd/core/types/list: V -> V<aa: V>, actionaction: (int, $2931) -> $2932 () : (intstd/core/types/int: V,aa: V) -> ee: E (std/core/types/unit: V)std/core/types/unit: V )result: -> 3043 () : ee: E (std/core/types/unit: V)std/core/types/unit: V var ii: local-var<$2941,int> := 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
xsxs: list<$2931>.foreachstd/core/list/foreach: (xs : list<$2931>, action : ($2931) -> <local<$2941>|$2932> ()) -> <local<$2941>|$2932> () fnfn: (x : $2931) -> <local<$2941>|$2932> ()(xx: $2931) val jj: int = ii: int // don't dereference `i` inside the inject mask<local_1: H>{ actionaction: (int, $2931) -> $2932 ()(jj: int,xx: $2931) } ii: local-var<$2941,int> :=std/core/types/local-set: (v : local-var<$2941,int>, assigned : int) -> <local<$2941>|$2932> () ii: int+std/core/int/(+): (x : int, y : int) -> <local<$2941>|$2932> 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<$3050> : liststd/core/types/list: V -> V<aa: V>, sepsep: $3050 : aa: V )result: -> total list<3113> : liststd/core/types/list: V -> V<aa: V> fun beforebefore: (ys : list<$3050>) -> list<$3050>(ysys: list<$3050>)result: -> total list<$3050> match ysys: list<$3050> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $3050,yyyy: list<$3050>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(sepsep: $3050,Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $3050,beforebefore: (ys : list<$3050>) -> list<$3050>(yyyy: list<$3050>))) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> match xsxs: list<$3050> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $3050,xxxx: list<$3050>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $3050, xxxx: list<$3050>.beforebefore: (ys : list<$3050>) -> list<$3050>) 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<$4634>> : liststd/core/types/list: V -> V<liststd/core/types/list: V -> V<aa: V>> )result: -> total list<4705> : 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<$4635> : liststd/core/types/list: V -> V<aa: V>, zsszss: list<list<$4635>> : liststd/core/types/list: V -> V<liststd/core/types/list: V -> V<aa: V>> )result: -> total list<4684> : liststd/core/types/list: V -> V<aa: V> match ysys: list<$4635> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $4635,yyyy: list<$4635>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $4635,concat-preconcat-pre: (ys : list<$4635>, zss : list<list<$4635>>) -> list<$4635>(yyyy: list<$4635>,zsszss: list<list<$4635>>)) Nilstd/core/types/Nil: forall<a> list<a> -> match zsszss: list<list<$4635>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(zszs: list<$4635>,zzszzs: list<list<$4635>>) -> concat-preconcat-pre: (ys : list<$4635>, zss : list<list<$4635>>) -> list<$4635>(zszs: list<$4635>,zzszzs: list<list<$4635>>) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> concat-preconcat-pre: (ys : list<$4634>, zss : list<list<$4634>>) -> list<$4634>([std/core/types/Nil: forall<a> list<a>]std/core/types/Nil: forall<a> list<a>,xssxss: list<list<$4634>>) // 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<$4710>: liststd/core/types/list: V -> V<aa: V>, ff: ($4710) -> $4712 list<$4711> : aa: V -> ee: E liststd/core/types/list: V -> V<bb: V> )result: -> 4775 list<4774> : ee: E liststd/core/types/list: V -> V<bb: V> fun flatmap-preflatmap-pre: (ys : list<$4711>, zs : list<$4710>) -> $4712 list<$4711>( ysys: list<$4711>, zszs: list<$4710> )result: -> $4712 list<$4711> match ysys: list<$4711> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $4711,yyyy: list<$4711>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $4711,flatmap-preflatmap-pre: (ys : list<$4711>, zs : list<$4710>) -> $4712 list<$4711>(yyyy: list<$4711>,zszs: list<$4710>)) Nilstd/core/types/Nil: forall<a> list<a> -> match zszs: list<$4710> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(zz: $4710,zzzz: list<$4710>) -> flatmap-preflatmap-pre: (ys : list<$4711>, zs : list<$4710>) -> $4712 list<$4711>(ff: ($4710) -> $4712 list<$4711>(zz: $4710),zzzz: list<$4710>) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> flatmap-preflatmap-pre: (ys : list<$4711>, zs : list<$4710>) -> $4712 list<$4711>([std/core/types/Nil: forall<a> list<a>]std/core/types/Nil: forall<a> list<a>,xsxs: list<$4710>) // 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<$4785> : liststd/core/types/list: V -> V<aa: V>, ff: ($4785) -> $4787 maybe<$4786> : aa: V -> ee: E maybestd/core/types/maybe: V -> V<bb: V> )result: -> 4854 list<4853> : ee: E liststd/core/types/list: V -> V<bb: V> match xsxs: list<$4785> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $4785,xxxx: list<$4785>) -> match ff: ($4785) -> $4787 maybe<$4786>(xx: $4785) Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $4786) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $4786, xxxx: list<$4785>.flatmap-maybestd/core/list/flatmap-maybe: (xs : list<$4785>, f : ($4785) -> $4787 maybe<$4786>) -> $4787 list<$4786>(ff: ($4785) -> $4787 maybe<$4786>)) Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<$4785>.flatmap-maybestd/core/list/flatmap-maybe: (xs : list<$4785>, f : ($4785) -> $4787 maybe<$4786>) -> $4787 list<$4786>(ff: ($4785) -> $4787 maybe<$4786>) 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<$4864>> : liststd/core/types/list: V -> V<maybestd/core/types/maybe: V -> V<aa: V>> )result: -> total list<4911> : liststd/core/types/list: V -> V<aa: V> match xsxs: list<maybe<$4864>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: maybe<$4864>,xxxx: list<maybe<$4864>>) -> match xx: maybe<$4864> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $4864) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $4864, xxxx: list<maybe<$4864>>.concat-maybestd/core/list/concat-maybe: (xs : list<maybe<$4864>>) -> list<$4864>) Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<maybe<$4864>>.concat-maybestd/core/list/concat-maybe: (xs : list<maybe<$4864>>) -> list<$4864> 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<$4916> : liststd/core/types/list: V -> V<aa: V> )result: -> total maybe<4953> : maybestd/core/types/maybe: V -> V<aa: V> match xsxs: list<$4916> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $4916,Nilstd/core/types/Nil: forall<a> list<a>) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $4916) Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,xxxx: list<$4916>) -> laststd/core/list/last: (xs : list<$4916>) -> maybe<$4916>(xxxx: list<$4916>) 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<$4958> : liststd/core/types/list: V -> V<aa: V> )result: -> total list<4991> : liststd/core/types/list: V -> V<aa: V> match xsxs: list<$4958> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $4958, xxxx: list<$4958> 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: $4958,initstd/core/list/init: (xs : list<$4958>) -> list<$4958>(xxxx: list<$4958>)) _ -> 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<$4996> : liststd/core/types/list: V -> V<aa: V>, nn: int : intstd/core/types/int: V )result: -> total maybe<5068> : maybestd/core/types/maybe: V -> V<aa: V> match xsxs: list<$4996> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $4996,xxxx: list<$4996>) -> if nn: int>std/core/int/(>): (x : int, y : int) -> bool0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
then xxxx: list<$4996>[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: $4996) 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<$5080> : liststd/core/types/list: V -> V<aa: V>, predicatepredicate: ($5080) -> $5081 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 5116 bool : ee: E boolstd/core/types/bool: V match xsxs: list<$5080> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $5080,xxxx: list<$5080>) -> if predicatepredicate: ($5080) -> $5081 bool(xx: $5080) then xxxx: list<$5080>.allstd/core/list/all: (xs : list<$5080>, predicate : ($5080) -> $5081 bool) -> $5081 bool(predicatepredicate: ($5080) -> $5081 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<$5123> : liststd/core/types/list: V -> V<aa: V>, predicatepredicate: ($5123) -> $5124 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 5159 bool : ee: E boolstd/core/types/bool: V match xsxs: list<$5123> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $5123,xxxx: list<$5123>) -> if predicatepredicate: ($5123) -> $5124 bool(xx: $5123) then Truestd/core/types/True: bool else xxxx: list<$5123>.anystd/core/list/any: (xs : list<$5123>, predicate : ($5123) -> $5124 bool) -> $5124 bool(predicatepredicate: ($5123) -> $5124 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) -> $1970 char : charstd/core/types/char: V -> ee: E charstd/core/types/char: V )result: -> 2018 string : ee: E stringstd/core/types/string: V ss: string.liststd/core/string/list: (s : string) -> $1970 list<char>.mapstd/core/list/map: (xs : list<char>, f : (char) -> $1970 char) -> $1970 list<char>(ff: (char) -> $1970 char).stringstd/core/string/listchar/string: (cs : list<char>) -> $1970 string // todo: optimize