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


// 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<$751> : liststd/core/types/list: V -> V<aa: V> )result: -> total maybe<772> : maybestd/core/types/maybe: V -> V<aa: V>
  match xsxs: list<$751>
    Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $751) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $751)
    _       -> 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<$1225> : liststd/core/types/list: V -> V<aa: V>, defaultdefault: $1225 : aa: V )result: -> total 1238 : astd/core/types/total: E
  match xsxs: list<$1225>
    Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1225) -> xx: $1225
    _       -> defaultdefault: $1225

// 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<$1122> : liststd/core/types/list: V -> V<aa: V> )result: -> total list<1137> : liststd/core/types/list: V -> V<aa: V>
  match xsxs: list<$1122>
    Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,xxxx: list<$1122>) -> xxxx: list<$1122>
    _          -> [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<$841> : liststd/core/types/list: V -> V<aa: V> )result: -> total bool : boolstd/core/types/bool: V
  match xsxs: list<$841>
    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: _1104)result: -> total list<3221>
  [std/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>xx: _1104]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<_890>)result: -> total int
  fun lenlen: forall<a> (ys : list<a>, acc : int) -> int(ysys: list<_870>,accacc: int)result: -> total int
    match ysys: list<_870>
      Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,yyyy: list<_870>) -> yyyy: list<_870>.lenlen: (ys : list<_870>, 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<_890>.lenlen: (ys : list<_890>, 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) -> $2763 $2762 : intstd/core/types/int: V -> ee: E aa: V )result: -> 2812 list<2811> : ee: E liststd/core/types/list: V -> V<aa: V> if lolo: int <=std/core/int/(<=): (x : int, y : int) -> $2763 bool hihi: int then Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>( ff: (int) -> $2763 $2762(lolo: int), liststd/core/list/function/list: (lo : int, hi : int, f : (int) -> $2763 $2762) -> $2763 list<$2762>( pretend-decreasingstd/core/undiv/pretend-decreasing: (x : int) -> $2763 int(lolo: int.incstd/core/int/inc: (i : int) -> $2763 int), hihi: int, ff: (int) -> $2763 $2762 )) 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) -> $2875 $2874 : intstd/core/types/int: V -> ee: E aa: V )result: -> 2926 list<2925> : ee: E liststd/core/types/list: V -> V<aa: V> if lolo: int <=std/core/int/(<=): (x : int, y : int) -> $2875 bool hihi: int then Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>( ff: (int) -> $2875 $2874(lolo: int), liststd/core/list/stridefunction/list: (lo : int, hi : int, stride : int, f : (int) -> $2875 $2874) -> $2875 list<$2874>( pretend-decreasingstd/core/undiv/pretend-decreasing: (x : int) -> $2875 int(lolo: int +std/core/int/(+): (x : int, y : int) -> $2875 int stridestride: int), hihi: int, stridestride: int, ff: (int) -> $2875 $2874 )) 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<$1294> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$1294> : liststd/core/types/list: V -> V<aa: V>, (@implicit/==)?(==): ($1294, $1294) -> bool : (aa: V,aa: V) -> boolstd/core/types/bool: V )result: -> total bool : boolstd/core/types/bool: V match xsxs: list<$1294> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1294,xxxx: list<$1294>) -> match ysys: list<$1294> 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: $1294,yyyy: list<$1294>) -> (xx: $1294==?(==): ($1294, $1294) -> boolyy: $1294) &&std/core/types/(&&): (x : bool, y : bool) -> bool (xxxx: list<$1294>==std/core/list/(==): (xs : list<$1294>, ys : list<$1294>, @implicit/(==) : ($1294, $1294) -> bool) -> bool
?(==)=?(==)
yyyy: list<$1294>) Nilstd/core/types/Nil: forall<a> list<a> -> match ysys: list<$1294> 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<$1507> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$1507> : liststd/core/types/list: V -> V<aa: V>, @implicit/cmp?cmp: ($1507, $1507) -> order : (aa: V,aa: V) -> orderstd/core/types/order: V )result: -> total order : orderstd/core/types/order: V match xsxs: list<$1507> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1507,xxxx: list<$1507>) -> match ysys: list<$1507> 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: $1507,yyyy: list<$1507>) -> match cmp?cmp: ($1507, $1507) -> order(xx: $1507,yy: $1507) Eqstd/core/types/Eq: order -> cmpstd/core/list/cmp: (xs : list<$1507>, ys : list<$1507>, @implicit/cmp : ($1507, $1507) -> order) -> order
?cmp=?cmp
(xxxx: list<$1507>,yyyy: list<$1507>) lglg: order -> lglg: order Nilstd/core/types/Nil: forall<a> list<a> -> match ysys: list<$1507> 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<$3582> : liststd/core/types/list: V -> V<aa: V>, @implicit/show?show: ($3582) -> $3583 string : aa: V -> ee: E stringstd/core/types/string: V )result: -> 3644 string : ee: E stringstd/core/types/string: V "["literal: string
count= 1
++std/core/types/(++): (x : string, y : string) -> $3583 string xsxs: list<$3582>.mapstd/core/list/map: (xs : list<$3582>, f : ($3582) -> $3583 string) -> $3583 list<string>(show?show: ($3582) -> $3583 string).joinstd/core/list/joinsep/join: (xs : list<string>, sep : string) -> $3583 string(","literal: string
count= 1
) ++std/core/types/(++): (x : string, y : string) -> $3583 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<$3661> : liststd/core/types/list: V -> V<aa: V>, show-elemshow-elem: ($3661) -> $3662 string : (aa: V) -> ee: E stringstd/core/types/string: V )result: -> 3679 string : ee: E stringstd/core/types/string: V showstd/core/list/show: (xs : list<$3661>, @implicit/show : ($3661) -> $3662 string) -> $3662 string(xsxs: list<$3661>,@implicit/show=show-elemshow-elem: ($3661) -> $3662 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<$4650> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$4651> : liststd/core/types/list: V -> V<bb: V> )result: -> total list<(4706, 4707)> : liststd/core/types/list: V -> V<(std/core/types/tuple2: (V, V) -> Vaa: V,bb: V)> match xsxs: list<$4650> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $4650,xxxx: list<$4650>) -> match ysys: list<$4651> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $4651,yyyy: list<$4651>) -> 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: $4650,yy: $4651)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b),zipstd/core/list/zip: (xs : list<$4650>, ys : list<$4651>) -> list<($4650, $4651)>(xxxx: list<$4650>,yyyy: list<$4651>)) 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<$4715> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$4716> :liststd/core/types/list: V -> V<bb: V>, ff: ($4715, $4716) -> $4718 $4717 : (aa: V,bb: V) -> ee: E cc: V )result: -> 4775 list<4774> : ee: E liststd/core/types/list: V -> V<cc: V> match xsxs: list<$4715> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $4715,xxxx: list<$4715>) -> match ysys: list<$4716> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $4716,yyyy: list<$4716>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: ($4715, $4716) -> $4718 $4717(xx: $4715,yy: $4716),zipwithstd/core/list/zipwith: (xs : list<$4715>, ys : list<$4716>, f : ($4715, $4716) -> $4718 $4717) -> $4718 list<$4717>(xxxx: list<$4715>,yyyy: list<$4716>,ff: ($4715, $4716) -> $4718 $4717)) 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<$1142> : liststd/core/types/list: V -> V<aa: V>, ys0ys0: list<$1143> :liststd/core/types/list: V -> V<bb: V>, ff: (int, $1142, $1143) -> $1145 $1144 : (intstd/core/types/int: V,aa: V,bb: V) -> ee: E cc: V )result: -> 1212 list<1211> : ee: E liststd/core/types/list: V -> V<cc: V> fun zipwith-iterzipwith-iter: (i : int, xs : list<$1142>, ys : list<$1143>) -> $1145 list<$1144>( ii: int, xsxs: list<$1142>, ysys: list<$1143> )result: -> $1145 list<$1144> match xsxs: list<$1142> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1142,xxxx: list<$1142>) -> match ysys: list<$1143> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $1143,yyyy: list<$1143>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (int, $1142, $1143) -> $1145 $1144(ii: int,xx: $1142,yy: $1143),zipwith-iterzipwith-iter: (i : int, xs : list<$1142>, ys : list<$1143>) -> $1145 list<$1144>(ii: int+std/core/int/(+): (x : int, y : int) -> $1145 int1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
,xxxx: list<$1142>,yyyy: list<$1143>)) 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<$1142>, ys : list<$1143>) -> $1145 list<$1144>(0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
,xs0xs0: list<$1142>,ys0ys0: list<$1143>
) // 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<($3849, $3850)> : liststd/core/types/list: V -> V<(std/core/types/tuple2: (V, V) -> Vaa: V,bb: V)> )result: -> total (list<4027>, list<4028>) : (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<(_3864, _3865)>, acc1acc1: cctx<_3906,list<_3864>>, acc2acc2: cctx<_3946,list<_3865>> )result: -> total (_3906, _3946) match ysys: list<(_3864, _3865)> 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: _3864,yy: _3865)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b),xxxx: list<(_3864, _3865)>) -> iteriter: (ys : list<(_3864, _3865)>, acc1 : cctx<_3906,list<_3864>>, acc2 : cctx<_3946,list<_3865>>) -> (_3906, _3946)(xxxx: list<(_3864, _3865)>,acc1acc1: cctx<_3906,list<_3864>> ++std/core/types/cctx/(++): (c1 : cctx<_3906,list<_3864>>, c2 : cctx<list<_3864>,list<_3864>>) -> cctx<_3906,list<_3864>> ctxctx: cctx<list<_3864>,list<_3864>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: _3864,_hole: list<_3864>),acc2acc2: cctx<_3946,list<_3865>> ++std/core/types/cctx/(++): (c1 : cctx<_3946,list<_3865>>, c2 : cctx<list<_3865>,list<_3865>>) -> cctx<_3946,list<_3865>> ctxctx: cctx<list<_3865>,list<_3865>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: _3865,_hole: list<_3865>)) Nilstd/core/types/Nil: forall<a> list<a> -> (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)acc1acc1: cctx<_3906,list<_3864>> ++.std/core/types/cctx/(++.): (c : cctx<_3906,list<_3864>>, x : list<_3864>) -> _3906 Nilstd/core/types/Nil: forall<a> list<a>,acc2acc2: cctx<_3946,list<_3865>> ++.std/core/types/cctx/(++.): (c : cctx<_3946,list<_3865>>, x : list<_3865>) -> _3946 Nilstd/core/types/Nil: forall<a> list<a>)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) iteriter: (ys : list<($3849, $3850)>, acc1 : cctx<list<$3849>,list<$3849>>, acc2 : cctx<list<$3850>,list<$3850>>) -> (list<$3849>, list<$3850>)(xsxs: list<($3849, $3850)>,ctxctx: ctx<list<$3849>> _hole: list<$3849>,ctxctx: ctx<list<$3850>> _hole: list<$3850>) // 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<($4036, $4037, $4038)> : liststd/core/types/list: V -> V<(std/core/types/tuple3: (V, V, V) -> Vaa: V,bb: V,cc: V)>)result: -> total (list<4290>, list<4291>, list<4292>) : (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<(_4054, _4055, _4056)>, acc1acc1: cctx<_4097,list<_4054>>, acc2acc2: cctx<_4137,list<_4055>>, acc3acc3: cctx<_4177,list<_4056>> )result: -> total (_4097, _4137, _4177) match ysys: list<(_4054, _4055, _4056)> 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: _4054,yy: _4055,zz: _4056)std/core/types/Tuple3: forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c),xxxx: list<(_4054, _4055, _4056)>) -> iteriter: (ys : list<(_4054, _4055, _4056)>, acc1 : cctx<_4097,list<_4054>>, acc2 : cctx<_4137,list<_4055>>, acc3 : cctx<_4177,list<_4056>>) -> (_4097, _4137, _4177)(xxxx: list<(_4054, _4055, _4056)>,acc1acc1: cctx<_4097,list<_4054>> ++std/core/types/cctx/(++): (c1 : cctx<_4097,list<_4054>>, c2 : cctx<list<_4054>,list<_4054>>) -> cctx<_4097,list<_4054>> ctxctx: cctx<list<_4054>,list<_4054>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: _4054,_hole: list<_4054>),acc2acc2: cctx<_4137,list<_4055>> ++std/core/types/cctx/(++): (c1 : cctx<_4137,list<_4055>>, c2 : cctx<list<_4055>,list<_4055>>) -> cctx<_4137,list<_4055>> ctxctx: cctx<list<_4055>,list<_4055>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: _4055,_hole: list<_4055>),acc3acc3: cctx<_4177,list<_4056>> ++std/core/types/cctx/(++): (c1 : cctx<_4177,list<_4056>>, c2 : cctx<list<_4056>,list<_4056>>) -> cctx<_4177,list<_4056>> ctxctx: cctx<list<_4056>,list<_4056>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(zz: _4056,_hole: list<_4056>)) 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<_4097,list<_4054>> ++.std/core/types/cctx/(++.): (c : cctx<_4097,list<_4054>>, x : list<_4054>) -> _4097 Nilstd/core/types/Nil: forall<a> list<a>,acc2acc2: cctx<_4137,list<_4055>> ++.std/core/types/cctx/(++.): (c : cctx<_4137,list<_4055>>, x : list<_4055>) -> _4137 Nilstd/core/types/Nil: forall<a> list<a>,acc3acc3: cctx<_4177,list<_4056>> ++.std/core/types/cctx/(++.): (c : cctx<_4177,list<_4056>>, x : list<_4056>) -> _4177 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<($4036, $4037, $4038)>, acc1 : cctx<list<$4036>,list<$4036>>, acc2 : cctx<list<$4037>,list<$4037>>, acc3 : cctx<list<$4038>,list<$4038>>) -> (list<$4036>, list<$4037>, list<$4038>)(xsxs: list<($4036, $4037, $4038)>,ctxctx: ctx<list<$4036>> _hole: list<$4036>,ctxctx: ctx<list<$4037>> _hole: list<$4037>,ctxctx: ctx<list<$4038>> _hole: list<$4038>) // 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<($4303, $4304, $4305, $4306)> : 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<4633>, list<4634>, list<4635>, list<4636>) : (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<(_4324, _4325, _4326, _4327)>, acc1acc1: cctx<_4368,list<_4324>>, acc2acc2: cctx<_4408,list<_4325>>, acc3acc3: cctx<_4448,list<_4326>>, acc4acc4: cctx<_4488,list<_4327>> )result: -> total (_4368, _4408, _4448, _4488) match ysys: list<(_4324, _4325, _4326, _4327)> 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: _4324,yy: _4325,zz: _4326,ww: _4327)std/core/types/Tuple4: forall<a,b,c,d> (fst : a, snd : b, thd : c, field4 : d) -> (a, b, c, d),xxxx: list<(_4324, _4325, _4326, _4327)>) -> iteriter: (ys : list<(_4324, _4325, _4326, _4327)>, acc1 : cctx<_4368,list<_4324>>, acc2 : cctx<_4408,list<_4325>>, acc3 : cctx<_4448,list<_4326>>, acc4 : cctx<_4488,list<_4327>>) -> (_4368, _4408, _4448, _4488)(xxxx: list<(_4324, _4325, _4326, _4327)>,acc1acc1: cctx<_4368,list<_4324>> ++std/core/types/cctx/(++): (c1 : cctx<_4368,list<_4324>>, c2 : cctx<list<_4324>,list<_4324>>) -> cctx<_4368,list<_4324>> ctxctx: cctx<list<_4324>,list<_4324>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: _4324,_hole: list<_4324>),acc2acc2: cctx<_4408,list<_4325>> ++std/core/types/cctx/(++): (c1 : cctx<_4408,list<_4325>>, c2 : cctx<list<_4325>,list<_4325>>) -> cctx<_4408,list<_4325>> ctxctx: cctx<list<_4325>,list<_4325>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: _4325,_hole: list<_4325>),acc3acc3: cctx<_4448,list<_4326>> ++std/core/types/cctx/(++): (c1 : cctx<_4448,list<_4326>>, c2 : cctx<list<_4326>,list<_4326>>) -> cctx<_4448,list<_4326>> ctxctx: cctx<list<_4326>,list<_4326>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(zz: _4326,_hole: list<_4326>),acc4acc4: cctx<_4488,list<_4327>> ++std/core/types/cctx/(++): (c1 : cctx<_4488,list<_4327>>, c2 : cctx<list<_4327>,list<_4327>>) -> cctx<_4488,list<_4327>> ctxctx: cctx<list<_4327>,list<_4327>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ww: _4327,_hole: list<_4327>)) 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<_4368,list<_4324>> ++.std/core/types/cctx/(++.): (c : cctx<_4368,list<_4324>>, x : list<_4324>) -> _4368 Nilstd/core/types/Nil: forall<a> list<a>,acc2acc2: cctx<_4408,list<_4325>> ++.std/core/types/cctx/(++.): (c : cctx<_4408,list<_4325>>, x : list<_4325>) -> _4408 Nilstd/core/types/Nil: forall<a> list<a>,acc3acc3: cctx<_4448,list<_4326>> ++.std/core/types/cctx/(++.): (c : cctx<_4448,list<_4326>>, x : list<_4326>) -> _4448 Nilstd/core/types/Nil: forall<a> list<a>,acc4acc4: cctx<_4488,list<_4327>> ++.std/core/types/cctx/(++.): (c : cctx<_4488,list<_4327>>, x : list<_4327>) -> _4488 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<($4303, $4304, $4305, $4306)>, acc1 : cctx<list<$4303>,list<$4303>>, acc2 : cctx<list<$4304>,list<$4304>>, acc3 : cctx<list<$4305>,list<$4305>>, acc4 : cctx<list<$4306>,list<$4306>>) -> (list<$4303>, list<$4304>, list<$4305>, list<$4306>)(xsxs: list<($4303, $4304, $4305, $4306)>,ctxctx: ctx<list<$4303>> _hole: list<$4303>,ctxctx: ctx<list<$4304>> _hole: list<$4304>,ctxctx: ctx<list<$4305>> _hole: list<$4305>,ctxctx: ctx<list<$4306>> _hole: list<$4306>) // 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<$2574> : liststd/core/types/list: V -> V<aa: V>, nn: int : intstd/core/types/int: V )result: -> total list<2612> : liststd/core/types/list: V -> V<aa: V> match xsxs: list<$2574> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2574,xxxx: list<$2574>) | 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: $2574, takestd/core/list/take: (xs : list<$2574>, n : int) -> list<$2574>(xxxx: list<$2574>, 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<$1621> : liststd/core/types/list: V -> V<aa: V>, nn: int : intstd/core/types/int: V )result: -> total list<1650> : liststd/core/types/list: V -> V<aa: V> match xsxs: list<$1621> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,xxxx: list<$1621>) | nn: int >std/core/int/(>): (x : int, y : int) -> bool 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
-> dropstd/core/list/drop: (xs : list<$1621>, n : int) -> list<$1621>(xxxx: list<$1621>, nn: int -std/core/int/(-): (x : int, y : int) -> int 1literal: int
dec = 1
hex8 = 0x01
bit8 = 0b00000001
) _ -> xsxs: list<$1621>
// 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<$2967> : liststd/core/types/list: V -> V<aa: V>, ff: ($2967) -> $2969 $2968 : aa: V -> ee: E bb: V)result: -> 3011 list<3010> : ee: E liststd/core/types/list: V -> V<bb: V> match xsxs: list<$2967> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2967,xxxx: list<$2967>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: ($2967) -> $2969 $2968(xx: $2967), xxxx: list<$2967>.mapstd/core/list/map: (xs : list<$2967>, f : ($2967) -> $2969 $2968) -> $2969 list<$2968>(ff: ($2967) -> $2969 $2968)) 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<$929> : liststd/core/types/list: V -> V<aa: V>, ff: (idx : int, value : $929) -> $931 $930 : (idx : intstd/core/types/int: V, value : aa: V) -> ee: E bb: V)result: -> 980 list<979> : ee: E liststd/core/types/list: V -> V<bb: V> fun map-idxmap-idx: (ys : list<$929>, i : int) -> $931 list<$930>(ysys: list<$929>,ii: int)result: -> $931 list<$930> match ysys: list<$929> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $929,yyyy: list<$929>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (idx : int, value : $929) -> $931 $930(ii: int,yy: $929), map-idxmap-idx: (ys : list<$929>, i : int) -> $931 list<$930>(yyyy: list<$929>,ii: int+std/core/int/(+): (x : int, y : int) -> $931 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<$929>, i : int) -> $931 list<$930>(xsxs: list<$929>,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<$1052> : liststd/core/types/list: V -> V<aa: V>, ff: (value : $1052, rest : list<$1052>) -> $1054 $1053 : (value : aa: V, rest : liststd/core/types/list: V -> V<aa: V>) -> ee: E bb: V)result: -> 1094 list<1093> : ee: E liststd/core/types/list: V -> V<bb: V> fun mappeekmappeek: (ys : list<$1052>) -> $1054 list<$1053>(ysys: list<$1052>)result: -> $1054 list<$1053> match ysys: list<$1052> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $1052,yyyy: list<$1052>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (value : $1052, rest : list<$1052>) -> $1054 $1053(yy: $1052,yyyy: list<$1052>), yyyy: list<$1052>.mappeekmappeek: (ys : list<$1052>) -> $1054 list<$1053>) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> mappeekmappeek: (ys : list<$1052>) -> $1054 list<$1053>(xsxs: list<$1052>) // 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<$990> : liststd/core/types/list: V -> V<aa: V>, ff: (idx : int, value : $990, rest : list<$990>) -> $992 $991 : (idx : intstd/core/types/int: V, value : aa: V, rest : liststd/core/types/list: V -> V<aa: V> ) -> ee: E bb: V)result: -> 1042 list<1041> : ee: E liststd/core/types/list: V -> V<bb: V> fun mapidxmapidx: (ys : list<$990>, i : int) -> $992 list<$991>(ysys: list<$990>,ii: int)result: -> $992 list<$991> match ysys: list<$990> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $990,yyyy: list<$990>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (idx : int, value : $990, rest : list<$990>) -> $992 $991(ii: int,yy: $990,yyyy: list<$990>), mapidxmapidx: (ys : list<$990>, i : int) -> $992 list<$991>(yyyy: list<$990>,ii: int+std/core/int/(+): (x : int, y : int) -> $992 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<$990>, i : int) -> $992 list<$991>(xsxs: list<$990>,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<$2109> : liststd/core/types/list: V -> V<aa: V>)result: -> total list<2124> : liststd/core/types/list: V -> V<aa: V> reverse-appendstd/core/list/reverse-append: (xs : list<$2109>, tl : list<$2109>) -> list<$2109>( xsxs: list<$2109>, 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<$701> : liststd/core/types/list: V -> V<aa: V>, tltl: list<$701> : liststd/core/types/list: V -> V<aa: V> )result: -> total list<746> : liststd/core/types/list: V -> V<aa: V> fun reverse-accreverse-acc: forall<a> (acc : list<a>, ys : list<a>) -> list<a>(accacc: list<$702> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$702> : liststd/core/types/list: V -> V<aa: V> )result: -> total list<729> : liststd/core/types/list: V -> V<aa: V> match ysys: list<$702> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $702,xxxx: list<$702>) -> reverse-accreverse-acc: (acc : list<$702>, ys : list<$702>) -> list<$702>(Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $702,accacc: list<$702>),xxxx: list<$702>) _ -> accacc: list<$702> reverse-accreverse-acc: (acc : list<$701>, ys : list<$701>) -> list<$701>(tltl: list<$701>,xsxs: list<$701>) // Append two lists. pub fun (++)std/core/list/(++): forall<a> (xs : list<a>, ys : list<a>) -> list<a>(xsxs: list<$1276> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$1276> : liststd/core/types/list: V -> V<aa: V> )result: -> total list<1289> : liststd/core/types/list: V -> V<aa: V> appendstd/core/list/append: (xs : list<$1276>, ys : list<$1276>) -> list<$1276>(xsxs: list<$1276>,ysys: list<$1276>) // Append two lists. pub fun appendstd/core/list/append: forall<a> (xs : list<a>, ys : list<a>) -> list<a>(xsxs: list<$1243> : liststd/core/types/list: V -> V<aa: V>, ysys: list<$1243> : liststd/core/types/list: V -> V<aa: V> )result: -> total list<1271> : liststd/core/types/list: V -> V<aa: V> match xsxs: list<$1243> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1243,xxxx: list<$1243>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1243,appendstd/core/list/append: (xs : list<$1243>, ys : list<$1243>) -> list<$1243>(xxxx: list<$1243>,ysys: list<$1243>)) Nilstd/core/types/Nil: forall<a> list<a> -> ysys: list<$1243> // 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<$2129> : liststd/core/types/list: V -> V<aa: V>, zz: $2130 : bb: V, ff: ($2129, $2130) -> $2131 $2130 : (aa: V, bb: V) -> ee: E bb: V)result: -> 2163 2162 : ee: E bb: V xsxs: list<$2129>.reversestd/core/list/reverse: (xs : list<$2129>) -> $2131 list<$2129>.foldlstd/core/list/foldl: (xs : list<$2129>, z : $2130, f : ($2130, $2129) -> $2131 $2130) -> $2131 $2130(zz: $2130) fnfn: (x : $2130, y : $2129) -> $2131 $2130(xx: $2130,yy: $2129) ff: ($2129, $2130) -> $2131 $2130(yy: $2129,xx: $2130) // 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<$2019> : liststd/core/types/list: V -> V<aa: V>, zz: $2020 : bb: V, ff: ($2020, $2019) -> $2021 $2020 : (bb: V, aa: V) -> ee: E bb: V)result: -> 2054 2053 : ee: E bb: V match xsxs: list<$2019> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2019,xxxx: list<$2019>) -> foldlstd/core/list/foldl: (xs : list<$2019>, z : $2020, f : ($2020, $2019) -> $2021 $2020) -> $2021 $2020(xxxx: list<$2019>,ff: ($2020, $2019) -> $2021 $2020(zz: $2020,xx: $2019),ff: ($2020, $2019) -> $2021 $2020) Nilstd/core/types/Nil: forall<a> list<a> -> zz: $2020 pub fun foldl1std/core/list/foldl1: forall<a,e> (xs : list<a>, f : (a, a) -> <exn|e> a) -> <exn|e> a(xsxs: list<$2064> : liststd/core/types/list: V -> V<aa: V>, ff: ($2064, $2064) -> <exn|$2065> $2064 : (aa: V,aa: V) -> <exnstd/core/exn/exn: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V)result: -> <exn|2102> 2101 : <exnstd/core/exn/exn: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V match xsxs: list<$2064> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2064,xxxx: list<$2064>) -> xxxx: list<$2064>.foldlstd/core/list/foldl: (xs : list<$2064>, z : $2064, f : ($2064, $2064) -> <exn|$2065> $2064) -> <exn|$2065> $2064(xx: $2064,ff: ($2064, $2064) -> <exn|$2065> $2064) Nilstd/core/types/Nil: forall<a> list<a> -> throwstd/core/exn/throw: (message : string, info : ? exception-info) -> <exn|$2065> $2064("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<$2173> : liststd/core/types/list: V -> V<aa: V>, ff: ($2173, $2173) -> <exn|$2174> $2173 : (aa: V,aa: V) -> <exnstd/core/exn/exn: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V)result: -> <exn|2196> 2195 : <exnstd/core/exn/exn: (E, V) -> V|std/core/types/effect-extend: (X, E) -> Eee: E> aa: V xsxs: list<$2173>.reversestd/core/list/reverse: (xs : list<$2173>) -> <exn|$2174> list<$2173>.foldl1std/core/list/foldl1: (xs : list<$2173>, f : ($2173, $2173) -> <exn|$2174> $2173) -> <exn|$2174> $2173(ff: ($2173, $2173) -> <exn|$2174> $2173) // Create a list of `n` repeated elements `x` pub fun replicatestd/core/list/replicate: forall<a> (x : a, n : int) -> list<a>( xx: $3514 : aa: V, nn: int : intstd/core/types/int: V )result: -> total list<3555> : 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: $3514, replicatestd/core/list/replicate: (x : $3514, n : int) -> list<$3514>(xx: $3514,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<$2617> : liststd/core/types/list: V -> V<aa: V>, nn: int : intstd/core/types/int: V )result: -> total (list<2647>, list<2647>) : (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<$2617>.takestd/core/list/take: (xs : list<$2617>, n : int) -> list<$2617>(nn: int), xsxs: list<$2617>.dropstd/core/list/drop: (xs : list<$2617>, n : int) -> list<$2617>(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<$3686> : liststd/core/types/list: V -> V<aa: V>, predicatepredicate: ($3686) -> $3687 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 3763 (list<3762>, list<3762>) : 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<$3686>, acc : list<$3686>) -> $3687 (list<$3686>, list<$3686>)( ysys: list<$3686>, accacc: list<$3686>)result: -> $3687 (list<$3686>, list<$3686>) match ysys: list<$3686> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $3686,yyyy: list<$3686>) -> if yy: $3686.predicatepredicate: ($3686) -> $3687 bool then yyyy: list<$3686>.span-accspan-acc: (ys : list<$3686>, acc : list<$3686>) -> $3687 (list<$3686>, list<$3686>)(Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $3686,accacc: list<$3686>)) else (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)accacc: list<$3686>.reversestd/core/list/reverse: (xs : list<$3686>) -> $3687 list<$3686>,ysys: list<$3686>)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<$3686>.reversestd/core/list/reverse: (xs : list<$3686>) -> $3687 list<$3686>, ysys: list<$3686>)std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b) xsxs: list<$3686>.span-accspan-acc: (ys : list<$3686>, acc : list<$3686>) -> $3687 (list<$3686>, list<$3686>)( [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<$3791> : liststd/core/types/list: V -> V<aa: V>, predicatepredicate: ($3791) -> $3792 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 3833 list<3832> : ee: E liststd/core/types/list: V -> V<aa: V> match xsxs: list<$3791> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $3791,xxxx: list<$3791>) -> if xx: $3791.predicatepredicate: ($3791) -> $3792 bool then Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $3791, xxxx: list<$3791>.take-whilestd/core/list/take-while: (xs : list<$3791>, predicate : ($3791) -> $3792 bool) -> $3792 list<$3791>(predicatepredicate: ($3791) -> $3792 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<$1655> : liststd/core/types/list: V -> V<aa: V>, predicatepredicate: ($1655) -> $1656 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 1688 list<1687> : ee: E liststd/core/types/list: V -> V<aa: V> match xsxs: list<$1655> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1655,xxxx: list<$1655>) -> if xx: $1655.predicatepredicate: ($1655) -> $1656 bool then xxxx: list<$1655>.drop-whilestd/core/list/drop-while: (xs : list<$1655>, predicate : ($1655) -> $1656 bool) -> $1656 list<$1655>(predicatepredicate: ($1655) -> $1656 bool) else xsxs: list<$1655> 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<$1695> : liststd/core/types/list: V -> V<aa: V>, predpred: ($1695) -> $1696 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 1743 list<1742> : ee: E liststd/core/types/list: V -> V<aa: V> match xsxs: list<$1695> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1695,xxxx: list<$1695>) -> if predpred: ($1695) -> $1696 bool(xx: $1695) then Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1695,xxxx: list<$1695>.filterstd/core/list/filter: (xs : list<$1695>, pred : ($1695) -> $1696 bool) -> $1696 list<$1695>(predpred: ($1695) -> $1696 bool)) else xxxx: list<$1695>.filterstd/core/list/filter: (xs : list<$1695>, pred : ($1695) -> $1696 bool) -> $1696 list<$1695>(predpred: ($1695) -> $1696 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<$3477> : liststd/core/types/list: V -> V<aa: V>, predpred: ($3477) -> $3478 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 3507 list<3506> : ee: E liststd/core/types/list: V -> V<aa: V> xsxs: list<$3477>.filterstd/core/list/filter: (xs : list<$3477>, pred : ($3477) -> $3478 bool) -> $3478 list<$3477>( fnfn: (x : $3477) -> $3478 bool(xx: $3477) !std/core/types/bool/(!): (b : bool) -> $3478 boolpredpred: ($3477) -> $3478 bool(xx: $3477) ) // 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<$3437> : liststd/core/types/list: V -> V<aa: V>, ^predpred: ($3437) -> $3438 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 3470 (list<3469>, list<3469>) : 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<$3437>, pred : ($3437) -> $3438 bool, acc1 : ctx<list<$3437>>, acc2 : ctx<list<$3437>>) -> $3438 (list<$3437>, list<$3437>)(xsxs: list<$3437>, predpred: ($3437) -> $3438 bool, ctxctx: ctx<list<$3437>> _hole: list<$3437>, ctxctx: ctx<list<$3437>> _hole: list<$3437>) 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<$3293> : liststd/core/types/list: V -> V<aa: V>, ^predpred: ($3293) -> $3294 bool : aa: V -> ee: E boolstd/core/types/bool: V, acc1acc1: ctx<list<$3293>> : ctxstd/core/types/ctx: V -> V<liststd/core/types/list: V -> V<aa: V>>, acc2acc2: ctx<list<$3293>> : ctxstd/core/types/ctx: V -> V<liststd/core/types/list: V -> V<aa: V>>)result: -> 3430 (list<3429>, list<3429>): 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<$3293> Nilstd/core/types/Nil: forall<a> list<a> -> (std/core/types/Tuple2: forall<a,b> (fst : a, snd : b) -> (a, b)acc1acc1: ctx<list<$3293>> ++.std/core/types/cctx/(++.): (c : cctx<list<$3293>,list<$3293>>, x : list<$3293>) -> $3294 list<$3293> Nilstd/core/types/Nil: forall<a> list<a>, acc2acc2: ctx<list<$3293>> ++.std/core/types/cctx/(++.): (c : cctx<list<$3293>,list<$3293>>, x : list<$3293>) -> $3294 list<$3293> 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: $3293,xxxx: list<$3293>) -> if predpred: ($3293) -> $3294 bool(xx: $3293) then partition-accstd/core/list/partition-acc: (xs : list<$3293>, pred : ($3293) -> $3294 bool, acc1 : ctx<list<$3293>>, acc2 : ctx<list<$3293>>) -> $3294 (list<$3293>, list<$3293>)(xxxx: list<$3293>,predpred: ($3293) -> $3294 bool,acc1acc1: ctx<list<$3293>> ++std/core/types/cctx/(++): (c1 : cctx<list<$3293>,list<$3293>>, c2 : cctx<list<$3293>,list<$3293>>) -> $3294 cctx<list<$3293>,list<$3293>> ctxctx: cctx<list<$3293>,list<$3293>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $3293,_hole: list<$3293>),acc2acc2: ctx<list<$3293>>) else partition-accstd/core/list/partition-acc: (xs : list<$3293>, pred : ($3293) -> $3294 bool, acc1 : ctx<list<$3293>>, acc2 : ctx<list<$3293>>) -> $3294 (list<$3293>, list<$3293>)(xxxx: list<$3293>,predpred: ($3293) -> $3294 bool,acc1acc1: ctx<list<$3293>>,acc2acc2: ctx<list<$3293>> ++std/core/types/cctx/(++): (c1 : cctx<list<$3293>,list<$3293>>, c2 : cctx<list<$3293>,list<$3293>>) -> $3294 cctx<list<$3293>,list<$3293>> ctxctx: cctx<list<$3293>,list<$3293>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $3293,_hole: list<$3293>)) // 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<$1750> : liststd/core/types/list: V -> V<aa: V>, predpred: ($1750) -> $1752 maybe<$1751> : aa: V -> ee: E maybestd/core/types/maybe: V -> V<bb: V> )result: -> 1811 list<1810> : ee: E liststd/core/types/list: V -> V<bb: V> match xsxs: list<$1750> 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: $1750,xxxx: list<$1750>) -> match predpred: ($1750) -> $1752 maybe<$1751>(xx: $1750) Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<$1750>.filter-mapstd/core/list/filter-map: (xs : list<$1750>, pred : ($1750) -> $1752 maybe<$1751>) -> $1752 list<$1751>(predpred: ($1750) -> $1752 maybe<$1751>) Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $1751) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $1751,xxxx: list<$1750>.filter-mapstd/core/list/filter-map: (xs : list<$1750>, pred : ($1750) -> $1752 maybe<$1751>) -> $1752 list<$1751>(predpred: ($1750) -> $1752 maybe<$1751>)) // 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<$1872> : liststd/core/types/list: V -> V<aa: V>, predpred: ($1872) -> $1873 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 1907 maybe<1906> : ee: E maybestd/core/types/maybe: V -> V<aa: V> xsxs: list<$1872>.foreach-whilestd/core/list/foreach-while: (xs : list<$1872>, action : ($1872) -> $1873 maybe<$1872>) -> $1873 maybe<$1872> fnfn: (x : $1872) -> $1873 maybe<$1872>(xx: $1872) if predpred: ($1872) -> $1873 bool(xx: $1872) then Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $1872) 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<$1914> : liststd/core/types/list: V -> V<aa: V>, predpred: ($1914) -> $1916 maybe<$1915> : aa: V -> ee: E maybestd/core/types/maybe: V -> V<bb: V> )result: -> 1938 maybe<1937> : ee: E maybestd/core/types/maybe: V -> V<bb: V> xsxs: list<$1914>.foreach-whilestd/core/list/foreach-while: (xs : list<$1914>, action : ($1914) -> $1916 maybe<$1915>) -> $1916 maybe<$1915>(predpred: ($1914) -> $1916 maybe<$1915>) // 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<($3052, $3053)> : liststd/core/types/list: V -> V<(std/core/types/tuple2: (V, V) -> Vaa: V,bb: V)>, predpred: ($3052) -> $3054 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 3161 maybe<3160> : ee: E maybestd/core/types/maybe: V -> V<bb: V> xsxs: list<($3052, $3053)>.foreach-whilestd/core/list/foreach-while: (xs : list<($3052, $3053)>, action : (($3052, $3053)) -> $3054 maybe<$3053>) -> $3054 maybe<$3053> fnfn: (kv : ($3052, $3053)) -> $3054 maybe<$3053>(kvkv: ($3052, $3053)) if predpred: ($3052) -> $3054 bool(kvkv: ($3052, $3053).fststd/core/types/tuple2/fst: (tuple2 : ($3052, $3053)) -> $3054 $3052) then Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(kvkv: ($3052, $3053).sndstd/core/types/tuple2/snd: (tuple2 : ($3052, $3053)) -> $3054 $3053) 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<$899> : maybestd/core/types/maybe: V -> V<aa: V> )result: -> total list<924> : liststd/core/types/list: V -> V<aa: V> match mm: maybe<$899> 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: $899) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $899,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<$2343> : liststd/core/types/list: V -> V<aa: V>, predpred: ($2343) -> $2344 bool : aa: V -> ee: E boolstd/core/types/bool: V, idxidx: int : intstd/core/types/int: V )result: -> 2379 int : ee: E intstd/core/types/int: V match xsxs: list<$2343> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2343,xxxx: list<$2343>) -> if predpred: ($2343) -> $2344 bool(xx: $2343) then idxidx: int else index-of-accstd/core/list/index-of-acc: (xs : list<$2343>, pred : ($2343) -> $2344 bool, idx : int) -> $2344 int(xxxx: list<$2343>,predpred: ($2343) -> $2344 bool,idxidx: int+std/core/int/(+): (x : int, y : int) -> $2344 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<$2386> : liststd/core/types/list: V -> V<aa: V>, predpred: ($2386) -> $2387 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 2404 int : ee: E intstd/core/types/int: V index-of-accstd/core/list/index-of-acc: (xs : list<$2386>, pred : ($2386) -> $2387 bool, idx : int) -> $2387 int( xsxs: list<$2386>, predpred: ($2386) -> $2387 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<$2203> : liststd/core/types/list: V -> V<aa: V>, actionaction: ($2203) -> $2204 () : (aa: V) -> ee: E (std/core/types/unit: V)std/core/types/unit: V )result: -> 2230 () : ee: E (std/core/types/unit: V)std/core/types/unit: V match xsxs: list<$2203> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2203,xxxx: list<$2203>) -> { actionaction: ($2203) -> $2204 ()(xx: $2203); xxxx: list<$2203>.foreachstd/core/list/foreach: (xs : list<$2203>, action : ($2203) -> $2204 ()) -> $2204 ()(actionaction: ($2203) -> $2204 ()) } 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<$1821> : liststd/core/types/list: V -> V<aa: V>, actionaction: ($1821) -> $1823 maybe<$1822> : (aa: V) -> ee: E maybestd/core/types/maybe: V -> V<bb: V> )result: -> 1862 maybe<1861> : ee: E maybestd/core/types/maybe: V -> V<bb: V> match xsxs: list<$1821> 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: $1821,xxxx: list<$1821>) -> match actionaction: ($1821) -> $1823 maybe<$1822>(xx: $1821) Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<$1821>.foreach-whilestd/core/list/foreach-while: (xs : list<$1821>, action : ($1821) -> $1823 maybe<$1822>) -> $1823 maybe<$1822>(actionaction: ($1821) -> $1823 maybe<$1822>) justjust: maybe<$1822> -> justjust: maybe<$1822> // 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<$3171> : liststd/core/types/list: V -> V<aa: V>, actionaction: ($3171) -> $3173 maybe<$3172> : (aa: V) -> ee: E maybestd/core/types/maybe: V -> V<bb: V> )result: -> 3223 list<3222> : ee: E liststd/core/types/list: V -> V<bb: V> match xsxs: list<$3171> 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: $3171,xxxx: list<$3171>) -> match actionaction: ($3171) -> $3173 maybe<$3172>(xx: $3171) Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $3172) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $3172,xxxx: list<$3171>.map-whilestd/core/list/map-while: (xs : list<$3171>, action : ($3171) -> $3173 maybe<$3172>) -> $3173 list<$3172>(actionaction: ($3171) -> $3173 maybe<$3172>)) 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<$2237> : liststd/core/types/list: V -> V<aa: V>, actionaction: (int, $2237) -> $2238 () : (intstd/core/types/int: V,aa: V) -> ee: E (std/core/types/unit: V)std/core/types/unit: V )result: -> 2336 () : ee: E (std/core/types/unit: V)std/core/types/unit: V var ii: local-var<$2247,int> := 0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
xsxs: list<$2237>.foreachstd/core/list/foreach: (xs : list<$2237>, action : ($2237) -> <local<$2247>|$2238> ()) -> <local<$2247>|$2238> () fnfn: (x : $2237) -> <local<$2247>|$2238> ()(xx: $2237) val jj: int = ii: int // don't dereference `i` inside the inject mask<local_1: H>{ actionaction: (int, $2237) -> $2238 ()(jj: int,xx: $2237) } ii: local-var<$2247,int> :=std/core/types/local-set: (v : local-var<$2247,int>, assigned : int) -> <local<$2247>|$2238> () ii: int+std/core/int/(+): (x : int, y : int) -> <local<$2247>|$2238> 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<$777> : liststd/core/types/list: V -> V<aa: V>, sepsep: $777 : aa: V )result: -> total list<836> : liststd/core/types/list: V -> V<aa: V> fun beforebefore: (ys : list<$777>) -> list<$777>(ysys: list<$777>)result: -> total list<$777> match ysys: list<$777> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $777,yyyy: list<$777>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(sepsep: $777,Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $777,beforebefore: (ys : list<$777>) -> list<$777>(yyyy: list<$777>))) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> match xsxs: list<$777> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $777,xxxx: list<$777>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $777, xxxx: list<$777>.beforebefore: (ys : list<$777>) -> list<$777>) 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 fun join-accjoin-acc: (ys : list<string>, acc : string) -> string( ysys: list<string> : liststd/core/types/list: V -> V<stringstd/core/types/string: V>, accacc: string : stringstd/core/types/string: V )result: -> total string : stringstd/core/types/string: V match ysys: list<string> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: string,yyyy: list<string>) -> join-accjoin-acc: (ys : list<string>, acc : string) -> string(yyyy: list<string>, accacc: string ++std/core/types/(++): (x : string, y : string) -> string sepsep: string ++std/core/types/(++): (x : string, y : string) -> string yy: string) // todo: use string builder Nilstd/core/types/Nil: forall<a> list<a> -> accacc: string 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,xxxx: list<string>) -> join-accjoin-acc: (ys : list<string>, acc : string) -> string(xxxx: list<string>,xx: 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 xsxs: list<string>.joinsepstd/core/list/joinsep: (xs : list<string>, sep : string) -> string(""literal: string
count= 0
) // 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>.joinsepstd/core/list/joinsep: (xs : list<string>, sep : string) -> string(""literal: string
count= 0
) // 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<$564>> : liststd/core/types/list: V -> V<liststd/core/types/list: V -> V<aa: V>> )result: -> total list<629> : 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<$565> : liststd/core/types/list: V -> V<aa: V>, zsszss: list<list<$565>> : liststd/core/types/list: V -> V<liststd/core/types/list: V -> V<aa: V>> )result: -> total list<610> : liststd/core/types/list: V -> V<aa: V> match ysys: list<$565> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $565,yyyy: list<$565>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $565,concat-preconcat-pre: (ys : list<$565>, zss : list<list<$565>>) -> list<$565>(yyyy: list<$565>,zsszss: list<list<$565>>)) Nilstd/core/types/Nil: forall<a> list<a> -> match zsszss: list<list<$565>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(zszs: list<$565>,zzszzs: list<list<$565>>) -> concat-preconcat-pre: (ys : list<$565>, zss : list<list<$565>>) -> list<$565>(zszs: list<$565>,zzszzs: list<list<$565>>) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> concat-preconcat-pre: (ys : list<$564>, zss : list<list<$564>>) -> list<$564>([std/core/types/Nil: forall<a> list<a>]std/core/types/Nil: forall<a> list<a>,xssxss: list<list<$564>>) // 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<$634>: liststd/core/types/list: V -> V<aa: V>, ff: ($634) -> $636 list<$635> : aa: V -> ee: E liststd/core/types/list: V -> V<bb: V> )result: -> 691 list<690> : ee: E liststd/core/types/list: V -> V<bb: V> fun flatmap-preflatmap-pre: (ys : list<$635>, zs : list<$634>) -> $636 list<$635>( ysys: list<$635>, zszs: list<$634> )result: -> $636 list<$635> match ysys: list<$635> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $635,yyyy: list<$635>) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $635,flatmap-preflatmap-pre: (ys : list<$635>, zs : list<$634>) -> $636 list<$635>(yyyy: list<$635>,zszs: list<$634>)) Nilstd/core/types/Nil: forall<a> list<a> -> match zszs: list<$634> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(zz: $634,zzzz: list<$634>) -> flatmap-preflatmap-pre: (ys : list<$635>, zs : list<$634>) -> $636 list<$635>(ff: ($634) -> $636 list<$635>(zz: $634),zzzz: list<$634>) Nilstd/core/types/Nil: forall<a> list<a> -> Nilstd/core/types/Nil: forall<a> list<a> flatmap-preflatmap-pre: (ys : list<$635>, zs : list<$634>) -> $636 list<$635>([std/core/types/Nil: forall<a> list<a>]std/core/types/Nil: forall<a> list<a>,xsxs: list<$634>) // 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<$1948> : liststd/core/types/list: V -> V<aa: V>, ff: ($1948) -> $1950 maybe<$1949> : aa: V -> ee: E maybestd/core/types/maybe: V -> V<bb: V> )result: -> 2009 list<2008> : ee: E liststd/core/types/list: V -> V<bb: V> match xsxs: list<$1948> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1948,xxxx: list<$1948>) -> match ff: ($1948) -> $1950 maybe<$1949>(xx: $1948) Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $1949) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $1949, xxxx: list<$1948>.flatmap-maybestd/core/list/flatmap-maybe: (xs : list<$1948>, f : ($1948) -> $1950 maybe<$1949>) -> $1950 list<$1949>(ff: ($1948) -> $1950 maybe<$1949>)) Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<$1948>.flatmap-maybestd/core/list/flatmap-maybe: (xs : list<$1948>, f : ($1948) -> $1950 maybe<$1949>) -> $1950 list<$1949>(ff: ($1948) -> $1950 maybe<$1949>) 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<$1573>> : liststd/core/types/list: V -> V<maybestd/core/types/maybe: V -> V<aa: V>> )result: -> total list<1616> : liststd/core/types/list: V -> V<aa: V> match xsxs: list<maybe<$1573>> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: maybe<$1573>,xxxx: list<maybe<$1573>>) -> match xx: maybe<$1573> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $1573) -> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $1573, xxxx: list<maybe<$1573>>.concat-maybestd/core/list/concat-maybe: (xs : list<maybe<$1573>>) -> list<$1573>) Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<maybe<$1573>>.concat-maybestd/core/list/concat-maybe: (xs : list<maybe<$1573>>) -> list<$1573> 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<$2536> : liststd/core/types/list: V -> V<aa: V> )result: -> total maybe<2569> : maybestd/core/types/maybe: V -> V<aa: V> match xsxs: list<$2536> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2536,Nilstd/core/types/Nil: forall<a> list<a>) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $2536) Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,xxxx: list<$2536>) -> laststd/core/list/last: (xs : list<$2536>) -> maybe<$2536>(xxxx: list<$2536>) 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<$2411> : liststd/core/types/list: V -> V<aa: V> )result: -> total list<2441> : liststd/core/types/list: V -> V<aa: V> match xsxs: list<$2411> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2411, xxxx: list<$2411> 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: $2411,initstd/core/list/init: (xs : list<$2411>) -> list<$2411>(xxxx: list<$2411>)) _ -> 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<$1367> : liststd/core/types/list: V -> V<aa: V>, nn: int : intstd/core/types/int: V )result: -> total maybe<1426> : maybestd/core/types/maybe: V -> V<aa: V> match xsxs: list<$1367> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1367,xxxx: list<$1367>) -> if nn: int>std/core/int/(>): (x : int, y : int) -> bool0literal: int
dec = 0
hex8 = 0x00
bit8 = 0b00000000
then xxxx: list<$1367>[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: $1367) 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<$1431> : liststd/core/types/list: V -> V<aa: V>, predicatepredicate: ($1431) -> $1432 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 1462 bool : ee: E boolstd/core/types/bool: V match xsxs: list<$1431> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1431,xxxx: list<$1431>) -> if predicatepredicate: ($1431) -> $1432 bool(xx: $1431) then xxxx: list<$1431>.allstd/core/list/all: (xs : list<$1431>, predicate : ($1431) -> $1432 bool) -> $1432 bool(predicatepredicate: ($1431) -> $1432 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<$1469> : liststd/core/types/list: V -> V<aa: V>, predicatepredicate: ($1469) -> $1470 bool : aa: V -> ee: E boolstd/core/types/bool: V )result: -> 1500 bool : ee: E boolstd/core/types/bool: V match xsxs: list<$1469> Consstd/core/types/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $1469,xxxx: list<$1469>) -> if predicatepredicate: ($1469) -> $1470 bool(xx: $1469) then Truestd/core/types/True: bool else xxxx: list<$1469>.anystd/core/list/any: (xs : list<$1469>, predicate : ($1469) -> $1470 bool) -> $1470 bool(predicatepredicate: ($1469) -> $1470 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) -> $2927 char : charstd/core/types/char: V -> ee: E charstd/core/types/char: V )result: -> 2966 string : ee: E stringstd/core/types/string: V ss: string.liststd/core/string/list: (s : string) -> $2927 list<char>.mapstd/core/list/map: (xs : list<char>, f : (char) -> $2927 char) -> $2927 list<char>(ff: (char) -> $2927 char).stringstd/core/string/listchar/string: (cs : list<char>) -> $2927 string // todo: optimize