/*---------------------------------------------------------------------------
  Copyright 2012-2021, 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.
---------------------------------------------------------------------------*/

/* Core functions.

   This module is implicitly imported and all functions and types
   are always available.
   Some types and operations are required to be defined for the compiler
   to work correctly (i.e. types like `:exn` or `:list`)
*/
module core

pub import types
pub import hnd

pub infixr 80  (^)
pub infixl 70  (*), (%), (/), cdiv, cmod
pub infixr 60  (++)
pub infixl 60  (+), (-)
pub infix  40  (!=), (==), (<=), (>=), (<), (>)
// prefix     (!), (-) 

extern import
  c  file "core/core-inline"
  cs file "core/core-inline.cs"
  js file "core/core-inline.js"

extern import
  js file "core/core-integer-inline.js"

extern import
  js file "core/core-string-inline.js"

extern import
  js file "core/core-console-inline.js"

// ----------------------------------------------------------------------------
// Builtin effects
// ----------------------------------------------------------------------------

// An alias for the empty effect.
pub alias totalstd/core/total: E = <std/core/types/(<>): E>

// The console effect signifies that a function may write to the console.
pub type consolestd/core/console: X :: X

// An alias for pure effects: a pure function always returns the same result
// when called with the same arguments but may not terminate or raise an exception.
pub alias purestd/core/pure: E = <std/core/types/(<>): Eexnstd/core/exn: HX,divstd/core/types/div: X>

// The `:global-scope` is a special type constant to denote the global scope
pub type global-scopestd/core/global-scope: S :: S

// The `:net` effect signifies a function may access the network
pub type netstd/core/net: X :: X

// The `:fsys` effect signifies a function may access the file system
pub type fsysstd/core/fsys: X :: X

// The `:ui` effect signifies a function may access the graphics system
pub type uistd/core/ui: X :: X

// The `:blocking` effect signifies that a function may block
pub type blockingstd/core/blocking: X :: X

// The `:io-total` effect is used for functions that perform arbitrary I/O operations, but are terminating without raising exceptions.
pub alias io-totalstd/core/io-total: E = <std/core/types/(<>): Endetstd/core/types/ndet: X,consolestd/core/console: X,netstd/core/net: X,fsysstd/core/fsys: X,uistd/core/ui: X,ststd/core/types/st: H -> E<globalstd/core/types/global: H>>

// The `:io-noexn` effect is used for functions that perform arbitrary I/O operations, but raise no exceptions
pub alias io-noexnstd/core/io-noexn: E = <std/core/types/(<>): Edivstd/core/types/div: X,io-totalstd/core/io-total: E>

// The `:io` effect is used for functions that perform arbitrary I/O operations.
pub alias iostd/core/io: E = <std/core/types/(<>): Eexnstd/core/exn: HX,io-noexnstd/core/io-noexn: E>

// ----------------------------------------------------------------------------
// Masking
// ----------------------------------------------------------------------------

// Add the state effect to a function effect.
pub inline extern inject-ststd/core/inject-st: forall<a,h,e> (() -> e a) -> total (() -> <st<h>|e> a) : forall<aa: V,hh: H,ee: E> (() -> ee: E aa: V) -> totalstd/core/total: E (() -> <ststd/core/types/st: H -> E<hh: H>|ee: E> aa: V)  
  inline "#1"

// ----------------------------------------------------------------------------
// Standard Functions
// ----------------------------------------------------------------------------

// The `const` funs returns its first argument and ignores the second.
pub fun conststd/core/const: forall<a,b> (x : a, y : b) -> a(xx: _2291,yy: _2292)
  xx: _2291

// Apply a function `f` to a specified argument `x`.
pub fun applystd/core/apply: forall<a,b,e> (f : (a) -> e b, x : a) -> e b(ff: (_2186) -> _2187 _2188,xx: _2186)
  ff: (_2186) -> _2187 _2188(xx: _2186)

// Compose two funs `f` and `g`.
pub fun ostd/core/o: forall<a,b,c,e> (f : (a) -> e b, g : (c) -> e a) -> ((x : c) -> e b)(ff: (_2812) -> _2809 _2810,gg: (_2808) -> _2809 _2812)
  fn(xx: _2808) ff: (_2812) -> _2809 _2810(gg: (_2808) -> _2809 _2812(xx: _2808))

// The `ignore` function ignores its argument.
pub fun ignorestd/core/ignore: forall<a> (x : a) -> ()( xx: $2614 : aa: V ) : (std/core/types/(): V)std/core/types/(): V
  (std/core/types/(): ())std/core/types/(): ()

// Return a 'constant' function that ignores its argument and always returns the same result
pub fun conststd/core/const.1: forall<a,b> (default : a) -> total ((x : b) -> a)( defaultdefault: $2297 : aa: V ) : totalstd/core/total: E (( x : bb: V ) -> astd/core/types/(<>): E)
  fn(_) defaultdefault: $2297 

// ----------------------------------------------------------------------------
// Standard Data types
// ----------------------------------------------------------------------------

pub fun intstd/core/int.8: (b : bool) -> int( bb: bool : boolstd/core/types/bool: V ) : intstd/core/types/int: V  
  if bb: bool then 1 else 0

pub fun mbintstd/core/mbint: (m : maybe<int>) -> int( mm: maybe<int> : maybestd/core/types/maybe: V -> V<intstd/core/types/int: V> ) : intstd/core/types/int: V
  match mm: maybe<int>
    Nothingstd/core/types/Nothing: forall<a> maybe<a> -> 0
    Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(ii: int) -> ii: int

// Convert an int to a boolean, using `False` for 0 and `True` otherwise.
pub fun boolstd/core/bool: (i : int) -> bool( ii: int : intstd/core/types/int: V ) : boolstd/core/types/bool: V 
  ii: int !=std/core/(!=).1: (x : int, y : int) -> bool 0

// Convert a `:maybe` type to a boolean using `False` for `Nothing` and `True` for `Just`.
pub fun boolstd/core/bool.1: forall<a> (m : maybe<a>) -> bool( mm: maybe<$10099> : maybestd/core/types/maybe: V -> V<aa: V> ) : boolstd/core/types/bool: V
  match mm: maybe<$10099>
    Nothingstd/core/types/Nothing: forall<a> maybe<a> -> Falsestd/core/types/False: bool
    _       -> Truestd/core/types/True: bool

// Convert a string to a boolean, using `False` for the empty string and `True` otherwise.
pub fun boolstd/core/bool.2: (s : string) -> bool( ss: string : stringstd/core/types/string: V ) : boolstd/core/types/bool: V  
  ss: string !=std/core/(!=).3: (string, string) -> bool ""

// Match a `:maybe` value and either return a default value on `Nothing` or apply a function to the value on `Just`
pub fun maybestd/core/maybe: forall<a,b,e> (m : maybe<a>, onNothing : b, onJust : (a) -> e b) -> e b( mm: maybe<$14444> : maybestd/core/types/maybe: V -> V<aa: V>, onNothingonNothing: $14445: bb: V, onJustonJust: ($14444) -> $14446 $14445: aa: V -> ee: E bb: V ) : ee: E bb: V
  match mm: maybe<$14444>
    Nothingstd/core/types/Nothing: forall<a> maybe<a> -> onNothingonNothing: $14445
    Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $14444) -> onJustonJust: ($14444) -> $14446 $14445(xx: $14444)

// Convert a `:maybe<a>` value to `:a`, using the `nothing` parameter for `Nothing`.
// This is an alias for `default`.
pub fun maybestd/core/maybe.1: forall<a> (m : maybe<a>, nothing : a) -> a( mm: maybe<$14467> : maybestd/core/types/maybe: V -> V<aa: V>, nothingnothing: $14467 : aa: V ) : astd/core/types/(<>): E
  defaultstd/core/default: forall<a> (m : maybe<a>, nothing : a) -> a(mm: maybe<$14467>,nothingnothing: $14467)

// Convert a `:maybe<a>` value to `:a`, using the `nothing` parameter for `Nothing`.
pub fun defaultstd/core/default: forall<a> (m : maybe<a>, nothing : a) -> a( mm: maybe<$2335> : maybestd/core/types/maybe: V -> V<aa: V>, nothingnothing: $2335 : aa: V ) : astd/core/types/(<>): E
  match mm: maybe<$2335>
    Nothingstd/core/types/Nothing: forall<a> maybe<a> -> nothingnothing: $2335
    Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $2335) -> xx: $2335

// Get the value of the `Just` constructor or raise an exception
pub fun unjuststd/core/unjust: forall<a> (m : maybe<a>) -> exn a( mm: maybe<$16554> : maybestd/core/types/maybe: V -> V<aa: V> ) : exnstd/core/exn: HX aa: V
  match mm: maybe<$16554>
    Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $16554) -> xx: $16554
    Nothingstd/core/types/Nothing: forall<a> maybe<a> -> throwstd/core/throw: forall<a> (message : string, info : ?exception-info) -> exn a("unexpected Nothing in std/core/unjust")

pub fun mapstd/core/map: forall<a,b,e> (m : maybe<a>, f : (a) -> e b) -> e maybe<b>( mm: maybe<$5350> : maybestd/core/types/maybe: V -> V<aa: V>, ff: ($5350) -> $5352 $5351 : aa: V -> ee: E bb: V ) : ee: E maybestd/core/types/maybe: V -> V<bb: V>
  match mm: maybe<$5350>
    Nothingstd/core/types/Nothing: forall<a> maybe<a> -> Nothingstd/core/types/Nothing: forall<a> maybe<a>
    Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $5350) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(ff: ($5350) -> $5352 $5351(xx: $5350))

pub fun (||)std/core/(||): forall<a> (m1 : maybe<a>, m2 : maybe<a>) -> maybe<a>( m1m1: maybe<$7687> : maybestd/core/types/maybe: V -> V<aa: V>, m2m2: maybe<$7687>: maybestd/core/types/maybe: V -> V<aa: V> ) : maybestd/core/types/maybe: V -> V<aa: V>
  match m1m1: maybe<$7687>
    Nothingstd/core/types/Nothing: forall<a> maybe<a> -> m2m2: maybe<$7687>
    _       -> m1m1: maybe<$7687>

// Convert a `:either` to a `:maybe` type discarding the value of the `Left` constructor
// and using `Just` for the `Right` constructor.
pub fun maybestd/core/maybe.2: forall<a,b> (e : either<a,b>) -> maybe<b>( ee: either<$14504,$14505> : eitherstd/core/types/either: (V, V) -> V<aa: V,bb: V> ) : maybestd/core/types/maybe: V -> V<bb: V>
  match ee: either<$14504,$14505>
    Leftstd/core/types/Left: forall<a,b> (left : a) -> either<a,b> -> Nothingstd/core/types/Nothing: forall<a> maybe<a>
    Rightstd/core/types/Right: forall<a,b> (right : b) -> either<a,b>(xx: $14505) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $14505)

// Map over the `Right` component of an `:either` type.
pub fun mapstd/core/map.1: forall<a,b,c,e> (e : either<a,b>, f : (b) -> e c) -> e either<a,c>( ee: either<$5377,$5378> : eitherstd/core/types/either: (V, V) -> V<aa: V,bb: V>, ff: ($5378) -> $5380 $5379 : bb: V -> ee: E cc: V  ) : ee: E eitherstd/core/types/either: (V, V) -> V<aa: V,cc: V>
  match ee: either<$5377,$5378>
    Rightstd/core/types/Right: forall<a,b> (right : b) -> either<a,b>(xx: $5378) -> Rightstd/core/types/Right: forall<a,b> (right : b) -> either<a,b>(ff: ($5378) -> $5380 $5379(xx: $5378))
    Leftstd/core/types/Left: forall<a,b> (left : a) -> either<a,b>(xx: $5377)  -> Leftstd/core/types/Left: forall<a,b> (left : a) -> either<a,b>(xx: $5377)

// The type of lists, which can be either empty (`Nil`) or an element followed
// by a list (`Cons`).
pub type liststd/core/list: V -> V<aa: V>
  // The empty list.
  con Nilstd/core/Nil: forall<a> list<a>
  // A ``head``  element followed by the ``tail``  of the list.
  con Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(headhead: 61:aa: V, tailtail: list<61> : liststd/core/list: V -> V<aa: V> )

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

// Return the head of list if the list is not empty, or use `default` otherwise
pub fun headstd/core/head.2: forall<a> (xs : list<a>, default : a) -> a( xsxs: list<$12924> : liststd/core/list: V -> V<aa: V>, defaultdefault: $12924 : aa: V ) : astd/core/types/(<>): E
  match xsxs: list<$12924>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $12924) -> xx: $12924
    _       -> defaultdefault: $12924

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

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

// A `:stream` is a co-inductive type representing an infinite list of elements.
pub co type streamstd/core/stream: V -> V<aa: V>
  con Nextstd/core/Next: forall<a> (head : a, tail : stream<a>) -> stream<a>(headhead: 79:aa: V, tailtail: stream<79>: streamstd/core/stream: V -> V<aa: V> )

pub fun intstd/core/int.9: (x : order) -> int( xx: order : orderstd/core/types/order: V ) : intstd/core/types/int: V
  match xx: order
    Ltstd/core/types/Lt: order -> -1
    Eqstd/core/types/Eq: order -> 0
    Gtstd/core/types/Gt: order -> 1

pub fun orderstd/core/order: (i : int) -> order( ii: int : intstd/core/types/int: V ) : orderstd/core/types/order: V
  if ii: int <std/core/(<).1: (x : int, y : int) -> bool 0 then Ltstd/core/types/Lt: order
  elif ii: int >std/core/(>).1: (x : int, y : int) -> bool 0 then Gtstd/core/types/Gt: order
  else Eqstd/core/types/Eq: order

pub fun (==)std/core/(==).4: (x : order, y : order) -> bool( xx: order : orderstd/core/types/order: V, yy: order : orderstd/core/types/order: V ) : boolstd/core/types/bool: V 
  xx: order.intstd/core/int.9: (x : order) -> int ==std/core/(==).1: (x : int, y : int) -> bool yy: order.intstd/core/int.9: (x : order) -> int 

pub fun (!=)std/core/(!=).4: (x : order, y : order) -> bool( xx: order : orderstd/core/types/order: V, yy: order : orderstd/core/types/order: V ) : boolstd/core/types/bool: V 
  xx: order.intstd/core/int.9: (x : order) -> int !=std/core/(!=).1: (x : int, y : int) -> bool yy: order.intstd/core/int.9: (x : order) -> int 

pub fun (>=)std/core/(>=).4: (x : order, y : order) -> bool( xx: order : orderstd/core/types/order: V, yy: order : orderstd/core/types/order: V ) : boolstd/core/types/bool: V 
  xx: order.intstd/core/int.9: (x : order) -> int >=std/core/(>=).1: (x : int, y : int) -> bool yy: order.intstd/core/int.9: (x : order) -> int 

pub fun (<=)std/core/(<=).5: (x : order, y : order) -> bool( xx: order : orderstd/core/types/order: V, yy: order : orderstd/core/types/order: V ) : boolstd/core/types/bool: V 
  xx: order.intstd/core/int.9: (x : order) -> int <=std/core/(<=).1: (x : int, y : int) -> bool yy: order.intstd/core/int.9: (x : order) -> int

pub fun (>)std/core/(>).3: (x : order, y : order) -> bool( xx: order : orderstd/core/types/order: V, yy: order : orderstd/core/types/order: V ) : boolstd/core/types/bool: V  
  xx: order.intstd/core/int.9: (x : order) -> int >std/core/(>).1: (x : int, y : int) -> bool yy: order.intstd/core/int.9: (x : order) -> int

pub fun (<)std/core/(<).5: (x : order, y : order) -> bool( xx: order : orderstd/core/types/order: V, yy: order : orderstd/core/types/order: V ) : boolstd/core/types/bool: V  
  xx: order.intstd/core/int.9: (x : order) -> int <std/core/(<).1: (x : int, y : int) -> bool yy: order.intstd/core/int.9: (x : order) -> int
  
pub fun mapstd/core/map.2: forall<a,b,e> (t : (a, a), f : (a) -> e b) -> e (b, b)( tt: ($5415, $5415) : (std/core/types/(,): (V, V) -> Vaa: V,aa: V)std/core/types/(,): (V, V) -> V, ff: ($5415) -> $5417 $5416 : aa: V -> ee: E bb: V ) : ee: E (std/core/types/(,): (V, V) -> Vbb: V, bb: V)std/core/types/(,): (V, V) -> V
  (std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)tt: ($5415, $5415).fststd/core/types/fst: forall<a,b> ((a, b)) -> a.ff: ($5415) -> $5417 $5416, tt: ($5415, $5415).sndstd/core/types/snd: forall<a,b> ((a, b)) -> b.ff: ($5415) -> $5417 $5416)std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)

pub fun mapstd/core/map.3: forall<a,b,e> (t : (a, a, a), f : (a) -> e b) -> e (b, b, b)( tt: ($5560, $5560, $5560) : (std/core/types/(,,): (V, V, V) -> Vaa: V,aa: V,aa: V)std/core/types/(,,): (V, V, V) -> V, ff: ($5560) -> $5562 $5561 : aa: V -> ee: E bb: V ) : ee: E (std/core/types/(,,): (V, V, V) -> Vbb: V, bb: V, bb: V)std/core/types/(,,): (V, V, V) -> V
  (std/core/types/(,,): forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c)tt: ($5560, $5560, $5560).fststd/core/types/fst.1: forall<a,b,c> ((a, b, c)) -> a.ff: ($5560) -> $5562 $5561, tt: ($5560, $5560, $5560).sndstd/core/types/snd.1: forall<a,b,c> ((a, b, c)) -> b.ff: ($5560) -> $5562 $5561, tt: ($5560, $5560, $5560).thdstd/core/types/thd: forall<a,b,c> ((a, b, c)) -> c.ff: ($5560) -> $5562 $5561)std/core/types/(,,): forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c)

pub fun mapstd/core/map.4: forall<a,b,e> (t : (a, a, a, a), f : (a) -> e b) -> e (b, b, b, b)( tt: ($5778, $5778, $5778, $5778) : (std/core/types/(,,,): (V, V, V, V) -> Vaa: V,aa: V,aa: V,aa: V)std/core/types/(,,,): (V, V, V, V) -> V, ff: ($5778) -> $5780 $5779 : aa: V -> ee: E bb: V ) : ee: E (std/core/types/(,,,): (V, V, V, V) -> Vbb: V,bb: V,bb: V,bb: V)std/core/types/(,,,): (V, V, V, V) -> V
  (std/core/types/(,,,): forall<a,b,c,d> (fst : a, snd : b, thd : c, field4 : d) -> (a, b, c, d)tt: ($5778, $5778, $5778, $5778).fststd/core/types/fst.2: forall<a,b,c,d> ((a, b, c, d)) -> a.ff: ($5778) -> $5780 $5779, tt: ($5778, $5778, $5778, $5778).sndstd/core/types/snd.2: forall<a,b,c,d> ((a, b, c, d)) -> b.ff: ($5778) -> $5780 $5779, tt: ($5778, $5778, $5778, $5778).thdstd/core/types/thd.1: forall<a,b,c,d> ((a, b, c, d)) -> c.ff: ($5778) -> $5780 $5779, tt: ($5778, $5778, $5778, $5778).field4std/core/types/field4: forall<a,b,c,d> ((a, b, c, d)) -> d.ff: ($5778) -> $5780 $5779)std/core/types/(,,,): forall<a,b,c,d> (fst : a, snd : b, thd : c, field4 : d) -> (a, b, c, d)

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

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

// Returns the length of a list.
pub fun lengthstd/core/length.1: forall<a> (xs : list<a>) -> int(xsxs: list<_4466>)
  fun lenlen: forall<a> (list<a>, int) -> int(ysys: list<_4439>,accacc: int)
    match ysys: list<_4439>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,yyyy: list<_4439>) -> yyyy: list<_4439>.lenlen: (list<_4439>, int) -> int(accacc: int+std/core/(+).4: (x : int, y : int) -> int1)
      Nilstd/core/Nil: forall<a> list<a>        -> accacc: int
  xsxs: list<_4466>.lenlen: forall<a> (list<a>, int) -> int(0)

// 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: (lo : int, hi : int) -> total list<int>( lolo: int: intstd/core/types/int: V, hihi: int: intstd/core/types/int: V ) : totalstd/core/total: E liststd/core/list: V -> V<intstd/core/types/int: V>
  if lolo: int <=std/core/(<=).1: (x : int, y : int) -> bool hihi: int
    then Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>( lolo: int, liststd/core/list: (lo : int, hi : int) -> total list<int>( unsafe-decreasingstd/core/types/unsafe-decreasing: forall<a> (x : a) -> a(lolo: int.incstd/core/inc: (i : int) -> int), hihi: int ) )
    else Nilstd/core/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 liststd/core/list.1: (lo : int, hi : int, stride : int) -> total list<int>( lolo: int: intstd/core/types/int: V, hihi: int: intstd/core/types/int: V, stridestride: int : intstd/core/types/int: V ) : totalstd/core/total: E liststd/core/list: V -> V<intstd/core/types/int: V>
  if lolo: int <=std/core/(<=).1: (x : int, y : int) -> bool hihi: int
    then Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>( lolo: int, liststd/core/list.1: (lo : int, hi : int, stride : int) -> total list<int>(  unsafe-decreasingstd/core/types/unsafe-decreasing: forall<a> (x : a) -> a(lolo: int +std/core/(+).4: (x : int, y : int) -> int stridestride: int), hihi: int, stridestride: int ))
    else Nilstd/core/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 liststd/core/list.2: 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) -> $4875 $4874 : intstd/core/types/int: V -> ee: E aa: V ) : ee: E liststd/core/list: V -> V<aa: V>
  if lolo: int <=std/core/(<=).1: (x : int, y : int) -> bool hihi: int
    then Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>( ff: (int) -> $4875 $4874(lolo: int), liststd/core/list.2: forall<a,e> (lo : int, hi : int, f : (int) -> e a) -> e list<a>( unsafe-decreasingstd/core/types/unsafe-decreasing: forall<a> (x : a) -> a(lolo: int.incstd/core/inc: (i : int) -> int), hihi: int, ff: (int) -> $4875 $4874 ))
    else Nilstd/core/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 liststd/core/list.3: 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) -> $4985 $4984 : intstd/core/types/int: V -> ee: E aa: V ) : ee: E liststd/core/list: V -> V<aa: V>
  if lolo: int <=std/core/(<=).1: (x : int, y : int) -> bool hihi: int
    then Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>( ff: (int) -> $4985 $4984(lolo: int), liststd/core/list.3: forall<a,e> (lo : int, hi : int, stride : int, f : (int) -> e a) -> e list<a>(  unsafe-decreasingstd/core/types/unsafe-decreasing: forall<a> (x : a) -> a(lolo: int +std/core/(+).4: (x : int, y : int) -> int stridestride: int), hihi: int, stridestride: int, ff: (int) -> $4985 $4984 ))
    else Nilstd/core/Nil: forall<a> list<a>  

// Create a list of characters from `lo`  to `hi`  (inclusive).
pub fun liststd/core/list.4: (lo : char, hi : char) -> total list<char>( lolo: char : charstd/core/types/char: V, hihi: char : charstd/core/types/char: V ) : totalstd/core/total: E liststd/core/list: V -> V<charstd/core/types/char: V>
  liststd/core/list: (lo : int, hi : int) -> total list<int>(lolo: char.intstd/core/int: (char) -> int, hihi: char.intstd/core/int: (char) -> int).mapstd/core/map.5: forall<a,b,e> (xs : list<a>, f : (a) -> e b) -> e list<b>( charstd/core/char: (i : int) -> char )

// 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/zip: forall<a,b> (xs : list<a>, ys : list<b>) -> list<(a, b)>( xsxs: list<$16770> : liststd/core/list: V -> V<aa: V>, ysys: list<$16771> : liststd/core/list: V -> V<bb: V> ) : liststd/core/list: V -> V<(std/core/types/(,): (V, V) -> Vaa: V,bb: V)std/core/types/(,): (V, V) -> V>
  match xsxs: list<$16770>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $16770,xxxx: list<$16770>) -> match ysys: list<$16771>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $16771,yyyy: list<$16771>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>((std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)xx: $16770,yy: $16771)std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b),zipstd/core/zip: forall<a,b> (xs : list<a>, ys : list<b>) -> list<(a, b)>(xxxx: list<$16770>,yyyy: list<$16771>))
      Nilstd/core/Nil: forall<a> list<a>        -> Nilstd/core/Nil: forall<a> list<a>
    Nilstd/core/Nil: forall<a> list<a> -> Nilstd/core/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/zipwith: forall<a,b,c,e> (xs : list<a>, ys : list<b>, f : (a, b) -> e c) -> e list<c>( xsxs: list<$16813> : liststd/core/list: V -> V<aa: V>, ysys: list<$16814> :liststd/core/list: V -> V<bb: V>, ff: ($16813, $16814) -> $16816 $16815 : (aa: V,bb: V) -> ee: E cc: V ) : ee: E liststd/core/list: V -> V<cc: V>
  match xsxs: list<$16813>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $16813,xxxx: list<$16813>) -> match ysys: list<$16814>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $16814,yyyy: list<$16814>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: ($16813, $16814) -> $16816 $16815(xx: $16813,yy: $16814),zipwithstd/core/zipwith: forall<a,b,c,e> (xs : list<a>, ys : list<b>, f : (a, b) -> e c) -> e list<c>(xxxx: list<$16813>,yyyy: list<$16814>,ff: ($16813, $16814) -> $16816 $16815))
      Nilstd/core/Nil: forall<a> list<a> -> Nilstd/core/Nil: forall<a> list<a>
    _ -> Nilstd/core/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/zipwith-indexed: forall<a,b,c,e> (xs0 : list<a>, ys0 : list<b>, f : (int, a, b) -> e c) -> e list<c>( xs0xs0: list<$16861> : liststd/core/list: V -> V<aa: V>, ys0ys0: list<$16862> :liststd/core/list: V -> V<bb: V>, ff: (int, $16861, $16862) -> $16864 $16863 : (intstd/core/types/int: V,aa: V,bb: V) -> ee: E cc: V ) : ee: E liststd/core/list: V -> V<cc: V>
  fun zipwith-iterzipwith-iter: (int, list<$16861>, list<$16862>) -> $16864 list<$16863>( ii: int, xsxs: list<$16861>, ysys: list<$16862> )
    match xsxs: list<$16861>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $16861,xxxx: list<$16861>) -> match ysys: list<$16862>
        Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $16862,yyyy: list<$16862>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (int, $16861, $16862) -> $16864 $16863(ii: int,xx: $16861,yy: $16862),zipwith-iterzipwith-iter: (int, list<$16861>, list<$16862>) -> $16864 list<$16863>(ii: int+std/core/(+).4: (x : int, y : int) -> int1,xxxx: list<$16861>,yyyy: list<$16862>))
        Nilstd/core/Nil: forall<a> list<a> -> Nilstd/core/Nil: forall<a> list<a>
      Nilstd/core/Nil: forall<a> list<a> -> Nilstd/core/Nil: forall<a> list<a>
  zipwith-iterzipwith-iter: (int, list<$16861>, list<$16862>) -> $16864 list<$16863>(0,xs0xs0: list<$16861>,ys0ys0: list<$16862>)

// Unzip a list of pairs into two lists
pub fun unzipstd/core/unzip: forall<a,b> (xs : list<(a, b)>) -> (list<a>, list<b>)( xsxs: list<($16589, $16590)> : liststd/core/list: V -> V<(std/core/types/(,): (V, V) -> Vaa: V,bb: V)std/core/types/(,): (V, V) -> V> ) : (std/core/types/(,): (V, V) -> Vliststd/core/list: V -> V<aa: V>,liststd/core/list: V -> V<bb: V>)std/core/types/(,): (V, V) -> V
  // todo: implement TRMC for multiple results
  fun iteriter: forall<a,b> (list<(a, b)>, list<a>, list<b>) -> (list<a>, list<b>)( ysys: list<(_16600, _16601)>, acc1acc1: list<_16600>, acc2acc2: list<_16601> )
    match ysys: list<(_16600, _16601)>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>((std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)xx: _16600,yy: _16601)std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b),xxxx: list<(_16600, _16601)>) -> iteriter: (list<(_16600, _16601)>, list<_16600>, list<_16601>) -> (list<_16600>, list<_16601>)(xxxx: list<(_16600, _16601)>,Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: _16600,acc1acc1: list<_16600>),Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: _16601,acc2acc2: list<_16601>))
      Nilstd/core/Nil: forall<a> list<a>            -> (std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)reversestd/core/reverse: forall<a> (xs : list<a>) -> list<a>(acc1acc1: list<_16600>),reversestd/core/reverse: forall<a> (xs : list<a>) -> list<a>(acc2acc2: list<_16601>))std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)
  iteriter: forall<a,b> (list<(a, b)>, list<a>, list<b>) -> (list<a>, list<b>)(xsxs: list<($16589, $16590)>,[std/core/Nil: forall<a> list<a>]std/core/Nil: forall<a> list<a>,[std/core/Nil: forall<a> list<a>]std/core/Nil: forall<a> list<a>)

// Take the first `n` elements of a list (or fewer if the list is shorter than `n`)
pub fun takestd/core/take: forall<a> (xs : list<a>, n : int) -> list<a>( xsxs: list<$13792> : liststd/core/list: V -> V<aa: V>, nn: int : intstd/core/types/int: V ) : liststd/core/list: V -> V<aa: V>
  match xsxs: list<$13792>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $13792,xxxx: list<$13792>) | nn: int >std/core/(>).1: (x : int, y : int) -> bool 0 -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $13792, takestd/core/take: forall<a> (xs : list<a>, n : int) -> list<a>(xxxx: list<$13792>, nn: int -std/core/(-).4: (x : int, y : int) -> int 1))
    _ -> Nilstd/core/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/drop: forall<a> (xs : list<a>, n : int) -> list<a>( xsxs: list<$11561> : liststd/core/list: V -> V<aa: V>, nn: int : intstd/core/types/int: V ) : liststd/core/list: V -> V<aa: V>
  match xsxs: list<$11561>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,xxxx: list<$11561>) | nn: int >std/core/(>).1: (x : int, y : int) -> bool 0 -> dropstd/core/drop: forall<a> (xs : list<a>, n : int) -> list<a>(xxxx: list<$11561>, nn: int -std/core/(-).4: (x : int, y : int) -> int 1)
    _ -> xsxs: list<$11561>

// Apply a function `f`  to each element of the input list in sequence.
pub fun mapstd/core/map.5: forall<a,b,e> (xs : list<a>, f : (a) -> e b) -> e list<b>(xsxs: list<$6065> : liststd/core/list: V -> V<aa: V>, ff: ($6065) -> $6067 $6066 : aa: V -> ee: E bb: V) : ee: E liststd/core/list: V -> V<bb: V>
  match xsxs: list<$6065>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $6065,xxxx: list<$6065>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: ($6065) -> $6067 $6066(xx: $6065), xxxx: list<$6065>.mapstd/core/map.5: forall<a,b,e> (xs : list<a>, f : (a) -> e b) -> e list<b>(ff: ($6065) -> $6067 $6066))
    Nilstd/core/Nil: forall<a> list<a> -> Nilstd/core/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/map-indexed: forall<a,b,e> (xs : list<a>, f : (idx : int, value : a) -> e b) -> e list<b>(xsxs: list<$14191> : liststd/core/list: V -> V<aa: V>, ff: (idx : int, value : $14191) -> $14193 $14192 : (idx : intstd/core/types/int: V, value : aa: V) -> ee: E bb: V) : ee: E liststd/core/list: V -> V<bb: V>
  fun map-idxmap-idx: (list<$14191>, int) -> $14193 list<$14192>(ysys: list<$14191>,ii: int)
    match ysys: list<$14191>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $14191,yyyy: list<$14191>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (idx : int, value : $14191) -> $14193 $14192(ii: int,yy: $14191), map-idxmap-idx: (list<$14191>, int) -> $14193 list<$14192>(yyyy: list<$14191>,ii: int+std/core/(+).4: (x : int, y : int) -> int1))
      Nilstd/core/Nil: forall<a> list<a> -> Nilstd/core/Nil: forall<a> list<a>
  map-idxmap-idx: (list<$14191>, int) -> $14193 list<$14192>(xsxs: list<$14191>,0)

// 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/map-peek: forall<a,b,e> (xs : list<a>, f : (value : a, rest : list<a>) -> e b) -> e list<b>(xsxs: list<$2732> : liststd/core/list: V -> V<aa: V>, ff: (value : $2732, rest : list<$2732>) -> $2734 $2733 : (value : aa: V, rest : liststd/core/list: V -> V<aa: V>) -> ee: E bb: V) : ee: E liststd/core/list: V -> V<bb: V>
  fun mappeekmappeek: (list<$2732>) -> $2734 list<$2733>(ysys: list<$2732>)
    match ysys: list<$2732>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2732,yyyy: list<$2732>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (value : $2732, rest : list<$2732>) -> $2734 $2733(yy: $2732,yyyy: list<$2732>), yyyy: list<$2732>.mappeekmappeek: (list<$2732>) -> $2734 list<$2733>)
      Nilstd/core/Nil: forall<a> list<a> -> Nilstd/core/Nil: forall<a> list<a>
  mappeekmappeek: (list<$2732>) -> $2734 list<$2733>(xsxs: list<$2732>)

// 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/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<$14247> : liststd/core/list: V -> V<aa: V>, ff: (idx : int, value : $14247, rest : list<$14247>) -> $14249 $14248 : (idx : intstd/core/types/int: V, value : aa: V, rest : liststd/core/list: V -> V<aa: V> ) -> ee: E bb: V) : ee: E liststd/core/list: V -> V<bb: V>
  fun mapidxmapidx: (list<$14247>, int) -> $14249 list<$14248>(ysys: list<$14247>,ii: int)
    match ysys: list<$14247>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $14247,yyyy: list<$14247>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (idx : int, value : $14247, rest : list<$14247>) -> $14249 $14248(ii: int,yy: $14247,yyyy: list<$14247>), mapidxmapidx: (list<$14247>, int) -> $14249 list<$14248>(yyyy: list<$14247>,ii: int+std/core/(+).4: (x : int, y : int) -> int1))
      Nilstd/core/Nil: forall<a> list<a> -> Nilstd/core/Nil: forall<a> list<a>
  mapidxmapidx: (list<$14247>, int) -> $14249 list<$14248>(xsxs: list<$14247>,0)

// Reverse a list.
pub fun reversestd/core/reverse: forall<a> (xs : list<a>) -> list<a>(xsxs: list<$12426> : liststd/core/list: V -> V<aa: V>) : liststd/core/list: V -> V<aa: V>
  reverse-appendstd/core/reverse-append: forall<a> (xs : list<a>, tl : list<a>) -> list<a>( xsxs: list<$12426>, Nilstd/core/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/reverse-append: forall<a> (xs : list<a>, tl : list<a>) -> list<a>( xsxs: list<$2459> : liststd/core/list: V -> V<aa: V>, tltl: list<$2459> : liststd/core/list: V -> V<aa: V> ) : liststd/core/list: V -> V<aa: V>
  fun reverse-accreverse-acc: forall<a> (acc : list<a>, ys : list<a>) -> list<a>(accacc: list<$2460> : liststd/core/list: V -> V<aa: V>, ysys: list<$2460> : liststd/core/list: V -> V<aa: V> ) : liststd/core/list: V -> V<aa: V>
    match ysys: list<$2460>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2460,xxxx: list<$2460>) -> reverse-accreverse-acc: forall<a> (acc : list<a>, ys : list<a>) -> list<a>(Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2460,accacc: list<$2460>),xxxx: list<$2460>)
      _          -> accacc: list<$2460>
  reverse-accreverse-acc: forall<a> (acc : list<a>, ys : list<a>) -> list<a>(tltl: list<$2459>,xsxs: list<$2459>)

// Append two lists.
pub fun (++)std/core/(++): forall<a> (xs : list<a>, ys : list<a>) -> list<a>(xsxs: list<$3225> : liststd/core/list: V -> V<aa: V>, ysys: list<$3225> : liststd/core/list: V -> V<aa: V> ) : liststd/core/list: V -> V<aa: V>
  appendstd/core/append: forall<a> (xs : list<a>, ys : list<a>) -> list<a>(xsxs: list<$3225>,ysys: list<$3225>)

// Append two lists.
pub fun appendstd/core/append: forall<a> (xs : list<a>, ys : list<a>) -> list<a>(xsxs: list<$3202> : liststd/core/list: V -> V<aa: V>, ysys: list<$3202> : liststd/core/list: V -> V<aa: V> ) : liststd/core/list: V -> V<aa: V>
  match xsxs: list<$3202>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $3202,xxxx: list<$3202>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $3202,appendstd/core/append: forall<a> (xs : list<a>, ys : list<a>) -> list<a>(xxxx: list<$3202>,ysys: list<$3202>))
    Nilstd/core/Nil: forall<a> list<a> -> ysys: list<$3202>

// 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/foldr: forall<a,b,e> (xs : list<a>, z : b, f : (a, b) -> e b) -> e b(xsxs: list<_12443>,zz: _12439,ff: (_12443, _12439) -> _12441 _12439)
  xsxs: list<_12443>.reversestd/core/reverse: forall<a> (xs : list<a>) -> list<a>.foldlstd/core/foldl: forall<a,b,e> (list<a>, b, (b, a) -> e b) -> e b(zz: _12439) fn(xx: _12439,yy: _12443) ff: (_12443, _12439) -> _12441 _12439(yy: _12443,xx: _12439)  

// 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/foldl: forall<a,b,e> (list<a>, b, (b, a) -> e b) -> e b(xsxs: list<_12370>,zz: _12365,ff: (_12365, _12370) -> _12367 _12365)
  match xsxs: list<_12370>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: _12370,xxxx: list<_12370>) -> foldlstd/core/foldl: (list<_12370>, _12365, (_12365, _12370) -> _12367 _12365) -> _12367 _12365(xxxx: list<_12370>,ff: (_12365, _12370) -> _12367 _12365(zz: _12365,xx: _12370),ff: (_12365, _12370) -> _12367 _12365)
    Nilstd/core/Nil: forall<a> list<a>        -> zz: _12365

pub fun foldl1std/core/foldl1: forall<a,e> (xs : list<a>, f : (a, a) -> <exn|e> a) -> <exn|e> a(xsxs: list<$12393> : liststd/core/list: V -> V<aa: V>, ff: ($12393, $12393) -> <exn|$12394> $12393 : (aa: V,aa: V) -> <exnstd/core/exn: HX|std/core/types/(<|>): (X, E) -> Eee: E> aa: V) : <exnstd/core/exn: HX|std/core/types/(<|>): (X, E) -> Eee: E> aa: V
  match xsxs: list<$12393>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $12393,xxxx: list<$12393>) -> xxxx: list<$12393>.foldlstd/core/foldl: forall<a,b,e> (list<a>, b, (b, a) -> e b) -> e b(xx: $12393,ff: ($12393, $12393) -> <exn|$12394> $12393)
    Nilstd/core/Nil: forall<a> list<a>        -> throwstd/core/throw: forall<a> (message : string, info : ?exception-info) -> exn a("unexpected Nil in std/core/foldl1")

pub fun foldr1std/core/foldr1: forall<a,e> (xs : list<a>, f : (a, a) -> <exn|e> a) -> <exn|e> a(xsxs: list<$12461> : liststd/core/list: V -> V<aa: V>, ff: ($12461, $12461) -> <exn|$12462> $12461 : (aa: V,aa: V) -> <exnstd/core/exn: HX|std/core/types/(<|>): (X, E) -> Eee: E> aa: V) : <exnstd/core/exn: HX|std/core/types/(<|>): (X, E) -> Eee: E> aa: V
  xsxs: list<$12461>.reversestd/core/reverse: forall<a> (xs : list<a>) -> list<a>.foldl1std/core/foldl1: forall<a,e> (xs : list<a>, f : (a, a) -> <exn|e> a) -> <exn|e> a(ff: ($12461, $12461) -> <exn|$12462> $12461)

// Create a list of `n`  repeated elementes `x`
pub fun replicatestd/core/replicate: forall<a> (x : a, n : int) -> list<a>( xx: $15773 : aa: V, nn: int : intstd/core/types/int: V ) : liststd/core/list: V -> V<aa: V>
  if nn: int >std/core/(>).1: (x : int, y : int) -> bool 0
   then Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $15773, replicatestd/core/replicate: forall<a> (x : a, n : int) -> list<a>(xx: $15773,unsafe-decreasingstd/core/types/unsafe-decreasing: forall<a> (x : a) -> a(nn: int.decstd/core/dec: (i : int) -> int)))
   else Nilstd/core/Nil: forall<a> list<a>

// split a list at position `n`
pub fun splitstd/core/split: forall<a> (xs : list<a>, n : int) -> (list<a>, list<a>)( xsxs: list<$13838> : liststd/core/list: V -> V<aa: V>, nn: int : intstd/core/types/int: V ) : (std/core/types/(,): (V, V) -> Vliststd/core/list: V -> V<aa: V>, liststd/core/list: V -> V<aa: V>)std/core/types/(,): (V, V) -> V
  (std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)xsxs: list<$13838>.takestd/core/take: forall<a> (xs : list<a>, n : int) -> list<a>(nn: int), xsxs: list<$13838>.dropstd/core/drop: forall<a> (xs : list<a>, n : int) -> list<a>(nn: int))std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)

pub fun spanstd/core/span: forall<a,e> (xs : list<a>, predicate : (a) -> e bool) -> e (list<a>, list<a>)( xsxs: list<$16131> : liststd/core/list: V -> V<aa: V>, predicatepredicate: ($16131) -> $16132 bool : aa: V -> ee: E boolstd/core/types/bool: V ) : ee: E (std/core/types/(,): (V, V) -> Vliststd/core/list: V -> V<aa: V>,liststd/core/list: V -> V<aa: V>)std/core/types/(,): (V, V) -> V
  // todo: implement TRMC with multiple results to avoid the reverse
  fun span-accspan-acc: (list<$16131>, list<$16131>) -> $16132 (list<$16131>, list<$16131>)( ysys: list<$16131>, accacc: list<$16131>)
    match ysys: list<$16131>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $16131,yyyy: list<$16131>) -> if yy: $16131.predicatepredicate: ($16131) -> $16132 bool then yyyy: list<$16131>.span-accspan-acc: (list<$16131>, list<$16131>) -> $16132 (list<$16131>, list<$16131>)(Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $16131,accacc: list<$16131>)) else (std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)accacc: list<$16131>.reversestd/core/reverse: forall<a> (xs : list<a>) -> list<a>,ysys: list<$16131>)std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)
      _ -> (std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)accacc: list<$16131>.reversestd/core/reverse: forall<a> (xs : list<a>) -> list<a>, ysys: list<$16131>)std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)
  xsxs: list<$16131>.span-accspan-acc: (list<$16131>, list<$16131>) -> $16132 (list<$16131>, list<$16131>)( [std/core/Nil: forall<a> list<a>]std/core/Nil: forall<a> list<a> )

// Keep only those initial elements that satisfy `predicate`
pub fun take-whilestd/core/take-while: forall<a,e> (xs : list<a>, predicate : (a) -> e bool) -> e list<a>( xsxs: list<$16267> : liststd/core/list: V -> V<aa: V>, predicatepredicate: ($16267) -> $16268 bool : aa: V -> ee: E boolstd/core/types/bool: V ) : ee: E liststd/core/list: V -> V<aa: V>
  match xsxs: list<$16267>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $16267,xxxx: list<$16267>) -> if xx: $16267.predicatepredicate: ($16267) -> $16268 bool then Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $16267, xxxx: list<$16267>.take-whilestd/core/take-while: forall<a,e> (xs : list<a>, predicate : (a) -> e bool) -> e list<a>(predicatepredicate: ($16267) -> $16268 bool) ) else Nilstd/core/Nil: forall<a> list<a>
    Nilstd/core/Nil: forall<a> list<a> -> Nilstd/core/Nil: forall<a> list<a>

// Drop all initial elements that satisfy `predicate`
pub fun drop-whilestd/core/drop-while: forall<a,e> (xs : list<a>, predicate : (a) -> e bool) -> e list<a>( xsxs: list<$11602> : liststd/core/list: V -> V<aa: V>, predicatepredicate: ($11602) -> $11603 bool : aa: V -> ee: E boolstd/core/types/bool: V ) : ee: E liststd/core/list: V -> V<aa: V>
  match xsxs: list<$11602>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $11602,xxxx: list<$11602>) -> if xx: $11602.predicatepredicate: ($11602) -> $11603 bool then xxxx: list<$11602>.drop-whilestd/core/drop-while: forall<a,e> (xs : list<a>, predicate : (a) -> e bool) -> e list<a>(predicatepredicate: ($11602) -> $11603 bool) else xsxs: list<$11602>
    Nilstd/core/Nil: forall<a> list<a> -> Nilstd/core/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/filter: forall<a,e> (xs : list<a>, pred : (a) -> e bool) -> e list<a>( xsxs: list<$11860> : liststd/core/list: V -> V<aa: V>, predpred: ($11860) -> $11861 bool : aa: V -> ee: E boolstd/core/types/bool: V ) : ee: E liststd/core/list: V -> V<aa: V>
  match xsxs: list<$11860>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $11860,xxxx: list<$11860>) -> if predpred: ($11860) -> $11861 bool(xx: $11860) then Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $11860,xxxx: list<$11860>.filterstd/core/filter: forall<a,e> (xs : list<a>, pred : (a) -> e bool) -> e list<a>(predpred: ($11860) -> $11861 bool)) else xxxx: list<$11860>.filterstd/core/filter: forall<a,e> (xs : list<a>, pred : (a) -> e bool) -> e list<a>(predpred: ($11860) -> $11861 bool)
    Nilstd/core/Nil: forall<a> list<a> -> Nilstd/core/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/remove: forall<a> (xs : list<a>, pred : (a) -> bool) -> list<a>( xsxs: list<$15715> : liststd/core/list: V -> V<aa: V>, predpred: ($15715) -> bool : aa: V -> boolstd/core/types/bool: V ) : liststd/core/list: V -> V<aa: V>
  xsxs: list<$15715>.filterstd/core/filter: forall<a,e> (xs : list<a>, pred : (a) -> e bool) -> e list<a>( fn(xx: $15715) !std/core/types/(!).1: (b : bool) -> boolpredpred: ($15715) -> bool(xx: $15715) )

// 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/partition: forall<a,e> (xs : list<a>, pred : (a) -> e bool) -> e (list<a>, list<a>)( xsxs: list<$15680> : liststd/core/list: V -> V<aa: V>, predpred: ($15680) -> $15681 bool : aa: V -> ee: E boolstd/core/types/bool: V ) : ee: E (std/core/types/(,): (V, V) -> Vliststd/core/list: V -> V<aa: V>,liststd/core/list: V -> V<aa: V>)std/core/types/(,): (V, V) -> V
  partition-accstd/core/partition-acc: forall<a,e> (xs : list<a>, pred : (a) -> e bool, acc1 : list<a>, acc2 : list<a>) -> e (list<a>, list<a>)( xsxs: list<$15680>, predpred: ($15680) -> $15681 bool, Nilstd/core/Nil: forall<a> list<a>, Nilstd/core/Nil: forall<a> list<a>)

fun partition-accstd/core/partition-acc: forall<a,e> (xs : list<a>, pred : (a) -> e bool, acc1 : list<a>, acc2 : list<a>) -> e (list<a>, list<a>)( xsxs: list<$15625> : liststd/core/list: V -> V<aa: V>, predpred: ($15625) -> $15626 bool : aa: V -> ee: E boolstd/core/types/bool: V, acc1acc1: list<$15625> : liststd/core/list: V -> V<aa: V>, acc2acc2: list<$15625> : liststd/core/list: V -> V<aa: V> ) : ee: E (std/core/types/(,): (V, V) -> Vliststd/core/list: V -> V<aa: V>, liststd/core/list: V -> V<aa: V>)std/core/types/(,): (V, V) -> V
  match xsxs: list<$15625>
    Nilstd/core/Nil: forall<a> list<a> -> (std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)acc1acc1: list<$15625>.reversestd/core/reverse: forall<a> (xs : list<a>) -> list<a>, acc2acc2: list<$15625>.reversestd/core/reverse: forall<a> (xs : list<a>) -> list<a>)std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $15625,xxxx: list<$15625>) -> if (predpred: ($15625) -> $15626 bool(xx: $15625))
                    then partition-accstd/core/partition-acc: forall<a,e> (xs : list<a>, pred : (a) -> e bool, acc1 : list<a>, acc2 : list<a>) -> e (list<a>, list<a>)(xxxx: list<$15625>,predpred: ($15625) -> $15626 bool,Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $15625,acc1acc1: list<$15625>),acc2acc2: list<$15625>)
                    else partition-accstd/core/partition-acc: forall<a,e> (xs : list<a>, pred : (a) -> e bool, acc1 : list<a>, acc2 : list<a>) -> e (list<a>, list<a>)(xxxx: list<$15625>,predpred: ($15625) -> $15626 bool,acc1acc1: list<$15625>,Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $15625,acc2acc2: list<$15625>))

// 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/filter-map: forall<a,b,e> (xs : list<a>, pred : (a) -> e maybe<b>) -> e list<b>( xsxs: list<$11897> : liststd/core/list: V -> V<aa: V>, predpred: ($11897) -> $11899 maybe<$11898> : aa: V -> ee: E maybestd/core/types/maybe: V -> V<bb: V> ) : ee: E liststd/core/list: V -> V<bb: V>
  match xsxs: list<$11897>
    Nilstd/core/Nil: forall<a> list<a> -> Nilstd/core/Nil: forall<a> list<a>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $11897,xxxx: list<$11897>) -> match predpred: ($11897) -> $11899 maybe<$11898>(xx: $11897)
      Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<$11897>.filter-mapstd/core/filter-map: forall<a,b,e> (xs : list<a>, pred : (a) -> e maybe<b>) -> e list<b>(predpred: ($11897) -> $11899 maybe<$11898>)
      Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $11898) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $11898,xxxx: list<$11897>.filter-mapstd/core/filter-map: forall<a,b,e> (xs : list<a>, pred : (a) -> e maybe<b>) -> e list<b>(predpred: ($11897) -> $11899 maybe<$11898>))

// Find the first element satisfying some predicate
pub fun findstd/core/find: forall<a> (xs : list<a>, pred : (a) -> bool) -> maybe<a>( xsxs: list<$11968> : liststd/core/list: V -> V<aa: V>, predpred: ($11968) -> bool : aa: V -> boolstd/core/types/bool: V ) : maybestd/core/types/maybe: V -> V<aa: V>
  xsxs: list<$11968>.foreach-whilestd/core/foreach-while: forall<a,b,e> (xs : list<a>, action : (a) -> e maybe<b>) -> e maybe<b> fn(xx: $11968)
    if predpred: ($11968) -> bool(xx: $11968) then Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $11968) else Nothingstd/core/types/Nothing: forall<a> maybe<a>

// Find the first element satisfying some predicate and return it.
pub fun find-maybestd/core/find-maybe: forall<a,b> (xs : list<a>, pred : (a) -> maybe<b>) -> maybe<b>( xsxs: list<$12136> : liststd/core/list: V -> V<aa: V>, predpred: ($12136) -> maybe<$12137> : aa: V -> maybestd/core/types/maybe: V -> V<bb: V> ) : maybestd/core/types/maybe: V -> V<bb: V>
  xsxs: list<$12136>.foreach-whilestd/core/foreach-while: forall<a,b,e> (xs : list<a>, action : (a) -> e maybe<b>) -> e maybe<b>(predpred: ($12136) -> maybe<$12137>)

// Lookup the first element satisfying some predicate
pub fun lookupstd/core/lookup: forall<a,b> (xs : list<(a, b)>, pred : (a) -> bool) -> maybe<b>( xsxs: list<($13991, $13992)> : liststd/core/list: V -> V<(std/core/types/(,): (V, V) -> Vaa: V,bb: V)std/core/types/(,): (V, V) -> V>, predpred: ($13991) -> bool : aa: V -> boolstd/core/types/bool: V ) : maybestd/core/types/maybe: V -> V<bb: V>
  xsxs: list<($13991, $13992)>.foreach-whilestd/core/foreach-while: forall<a,b,e> (xs : list<a>, action : (a) -> e maybe<b>) -> e maybe<b> fn(kvkv: ($13991, $13992))
    if predpred: ($13991) -> bool(kvkv: ($13991, $13992).fststd/core/types/fst: forall<a,b> ((a, b)) -> a) then Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(kvkv: ($13991, $13992).sndstd/core/types/snd: forall<a,b> ((a, b)) -> b) else Nothingstd/core/types/Nothing: forall<a> maybe<a>

// Convert a list to a `:maybe` type, using `Nothing` for an empty list, and otherwise `Just` on the head element.
// Note: this is just `head`.
pub fun maybestd/core/maybe.3: forall<a> (xs : list<a>) -> maybe<a>( xsxs: list<$14554> : liststd/core/list: V -> V<aa: V> ) : maybestd/core/types/maybe: V -> V<aa: V>
  match xsxs: list<$14554>
    Nilstd/core/Nil: forall<a> list<a> -> Nothingstd/core/types/Nothing: forall<a> maybe<a>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $14554,_) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $14554)

// Convert a `:maybe` type to a list type.
pub fun liststd/core/list.5: forall<a> (m : maybe<a>) -> list<a>( mm: maybe<$5312> : maybestd/core/types/maybe: V -> V<aa: V> ) : liststd/core/list: V -> V<aa: V>
  match mm: maybe<$5312>
    Nothingstd/core/types/Nothing: forall<a> maybe<a> -> Nilstd/core/Nil: forall<a> list<a>
    Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $5312) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $5312,Nilstd/core/Nil: forall<a> list<a>)

fun index-of-accstd/core/index-of-acc: forall<a> (xs : list<a>, pred : (a) -> bool, idx : int) -> int( xsxs: list<$13044> : liststd/core/list: V -> V<aa: V>, predpred: ($13044) -> bool : aa: V -> boolstd/core/types/bool: V, idxidx: int : intstd/core/types/int: V ) : intstd/core/types/int: V
  match xsxs: list<$13044>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $13044,xxxx: list<$13044>) -> if predpred: ($13044) -> bool(xx: $13044) then idxidx: int else index-of-accstd/core/index-of-acc: forall<a> (xs : list<a>, pred : (a) -> bool, idx : int) -> int(xxxx: list<$13044>,predpred: ($13044) -> bool,idxidx: int+std/core/(+).4: (x : int, y : int) -> int1)
    Nilstd/core/Nil: forall<a> list<a>        -> -1
    

// Returns the index of the first element where `pred` holds, or `-1` if no such element exists.
pub fun index-ofstd/core/index-of: forall<a> (xs : list<a>, pred : (a) -> bool) -> int( xsxs: list<$13083> : liststd/core/list: V -> V<aa: V>, predpred: ($13083) -> bool : aa: V -> boolstd/core/types/bool: V ) : intstd/core/types/int: V
  index-of-accstd/core/index-of-acc: forall<a> (xs : list<a>, pred : (a) -> bool, idx : int) -> int( xsxs: list<$13083>, predpred: ($13083) -> bool, 0 )

// Invoke `action` for each element of a list
pub fun foreachstd/core/foreach: forall<a,e> (xs : list<a>, action : (a) -> e ()) -> e ()( xsxs: list<$11001> : liststd/core/list: V -> V<aa: V>, actionaction: ($11001) -> $11002 () : (aa: V) -> ee: E (std/core/types/(): V)std/core/types/(): V ) : ee: E (std/core/types/(): V)std/core/types/(): V
  match xsxs: list<$11001>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $11001,xxxx: list<$11001>) -> { actionaction: ($11001) -> $11002 ()(xx: $11001); xxxx: list<$11001>.foreachstd/core/foreach: forall<a,e> (xs : list<a>, action : (a) -> e ()) -> e ()(actionaction: ($11001) -> $11002 ()) }
    Nilstd/core/Nil: forall<a> list<a>        -> (std/core/types/(): ())std/core/types/(): ()    

// Invoke `action` for each element of a list while `action` return `Nothing`
pub fun foreach-whilestd/core/foreach-while: forall<a,b,e> (xs : list<a>, action : (a) -> e maybe<b>) -> e maybe<b>( xsxs: list<$10595> : liststd/core/list: V -> V<aa: V>, actionaction: ($10595) -> $10597 maybe<$10596> : (aa: V) -> ee: E maybestd/core/types/maybe: V -> V<bb: V> ) : ee: E maybestd/core/types/maybe: V -> V<bb: V>
  match xsxs: list<$10595>
    Nilstd/core/Nil: forall<a> list<a>        -> Nothingstd/core/types/Nothing: forall<a> maybe<a>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $10595,xxxx: list<$10595>) ->
      match actionaction: ($10595) -> $10597 maybe<$10596>(xx: $10595)
        Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<$10595>.foreach-whilestd/core/foreach-while: forall<a,b,e> (xs : list<a>, action : (a) -> e maybe<b>) -> e maybe<b>(actionaction: ($10595) -> $10597 maybe<$10596>)
        justjust: maybe<$10596>    -> justjust: maybe<$10596>      

// Invoke `action` on each element of a list while `action` returns `Just`
pub fun map-whilestd/core/map-while: forall<a,b,e> (xs : list<a>, action : (a) -> e maybe<b>) -> e list<b>( xsxs: list<$14304> : liststd/core/list: V -> V<aa: V>, actionaction: ($14304) -> $14306 maybe<$14305> : (aa: V) -> ee: E maybestd/core/types/maybe: V -> V<bb: V> ) : ee: E liststd/core/list: V -> V<bb: V>
  match xsxs: list<$14304>
    Nilstd/core/Nil: forall<a> list<a>        -> Nilstd/core/Nil: forall<a> list<a>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $14304,xxxx: list<$14304>) ->
      match actionaction: ($14304) -> $14306 maybe<$14305>(xx: $14304)
        Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $14305) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $14305,xxxx: list<$14304>.map-whilestd/core/map-while: forall<a,b,e> (xs : list<a>, action : (a) -> e maybe<b>) -> e list<b>(actionaction: ($14304) -> $14306 maybe<$14305>))
        Nothingstd/core/types/Nothing: forall<a> maybe<a> -> Nilstd/core/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/foreach-indexed: forall<a,e> (xs : list<a>, action : (int, a) -> e ()) -> e ()( xsxs: list<$12566> : liststd/core/list: V -> V<aa: V>, actionaction: (int, $12566) -> $12567 () : (intstd/core/types/int: V,aa: V) -> ee: E (std/core/types/(): V)std/core/types/(): V ) : ee: E (std/core/types/(): V)std/core/types/(): V
  varstd/core/hnd/local-var: forall<a,b,e,h> (init : a, action : (l : local-var<h,a>) -> <local<h>|e> b) -> <local<h>|e> b istd/core/types/local-scope: forall<a,e> (action : forall<h> () -> <local<h>|e> a) -> e a := 0
  xsxs: list<$12566>.foreachstd/core/foreach: forall<a,e> (xs : list<a>, action : (a) -> e ()) -> e () fn(xx: $12566)
    val jj: int = ii: int // don't dereference `i` inside the inject
    mask_1: H<localstd/core/types/local: H -> X>{ actionaction: (int, $12566) -> $12567 ()(jj: int,xx: $12566) }
    ii: local-var<$12571,int> :=std/core/types/local-set: forall<a,e,h> (v : local-var<h,a>, assigned : a) -> <local<h>|e> () ii: int+std/core/(+).4: (x : int, y : int) -> int1

// Insert a separator `sep`  between all elements of a list `xs` .
pub fun interspersestd/core/intersperse: forall<a> (xs : list<a>, sep : a) -> list<a>( xsxs: list<$2631> : liststd/core/list: V -> V<aa: V>, sepsep: $2631 : aa: V ) : liststd/core/list: V -> V<aa: V>
  fun beforebefore: (list<$2631>) -> list<$2631>(ysys: list<$2631>)
    match ysys: list<$2631>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2631,yyyy: list<$2631>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(sepsep: $2631,Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2631,beforebefore: (list<$2631>) -> list<$2631>(yyyy: list<$2631>)))
      Nilstd/core/Nil: forall<a> list<a>        -> Nilstd/core/Nil: forall<a> list<a>
  match xsxs: list<$2631>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2631,xxxx: list<$2631>)  -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2631, xxxx: list<$2631>.beforebefore: (list<$2631>) -> list<$2631>)
    Nilstd/core/Nil: forall<a> list<a>         -> Nilstd/core/Nil: forall<a> list<a>

// Concatenate all strings in a list
fun joinsepstd/core/joinsep: (xs : list<string>, sep : string) -> string( xsxs: list<string> : liststd/core/list: V -> V<stringstd/core/types/string: V>, sepsep: string : stringstd/core/types/string: V ) : stringstd/core/types/string: V
  fun join-accjoin-acc: (ys : list<string>, acc : string) -> string( ysys: list<string> : liststd/core/list: V -> V<stringstd/core/types/string: V>, accacc: string : stringstd/core/types/string: V )
    match ysys: list<string>
      Consstd/core/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/(++).1: (x : string, y : string) -> string sepsep: string ++std/core/(++).1: (x : string, y : string) -> string yy: string)  // todo: use string builder
      Nilstd/core/Nil: forall<a> list<a> -> accacc: string
  match xsxs: list<string>
    Nilstd/core/Nil: forall<a> list<a> -> ""
    Consstd/core/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/join.2: (xs : list<string>) -> string( xsxs: list<string> : liststd/core/list: V -> V<stringstd/core/types/string: V> ) : stringstd/core/types/string: V
  xsxs: list<string>.joinsepstd/core/joinsep: (xs : list<string>, sep : string) -> string("")

// Concatenate all strings in a list using a specific separator
pub fun joinstd/core/join.3: (xs : list<string>, sep : string) -> string( xsxs: list<string> : liststd/core/list: V -> V<stringstd/core/types/string: V>, sepsep: string : stringstd/core/types/string: V ) : stringstd/core/types/string: V
  xsxs: list<string>.joinsepstd/core/joinsep: (xs : list<string>, sep : string) -> string(sepsep: string)

// Concatenate all strings in a list in reverse order
pub fun reverse-joinstd/core/reverse-join: (xs : list<string>) -> string( xsxs: list<string> : liststd/core/list: V -> V<stringstd/core/types/string: V> ) : stringstd/core/types/string: V
  xsxs: list<string>.reversestd/core/reverse: forall<a> (xs : list<a>) -> list<a>.joinsepstd/core/joinsep: (xs : list<string>, sep : 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/join-end: (xs : list<string>, end : string) -> string( xsxs: list<string> : liststd/core/list: V -> V<stringstd/core/types/string: V>, endend: string : stringstd/core/types/string: V) : stringstd/core/types/string: V
  match xsxs: list<string>
    Nilstd/core/Nil: forall<a> list<a> -> ""
    _   -> xsxs: list<string>.joinsepstd/core/joinsep: (xs : list<string>, sep : string) -> string(endend: string) ++std/core/(++).1: (x : string, y : string) -> string endend: string

// Concatenate all lists in a list (e.g. flatten the list). (tail-recursive)
pub fun concatstd/core/concat: forall<a> (xss : list<list<a>>) -> list<a>( xssxss: list<list<$2239>> : liststd/core/list: V -> V<liststd/core/list: V -> V<aa: V>> ) : liststd/core/list: V -> V<aa: V>
  fun concat-preconcat-pre: forall<a> (ys : list<a>, zss : list<list<a>>) -> list<a>( ysys: list<$2240> : liststd/core/list: V -> V<aa: V>, zsszss: list<list<$2240>> : liststd/core/list: V -> V<liststd/core/list: V -> V<aa: V>> ) : liststd/core/list: V -> V<aa: V>
    match ysys: list<$2240>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2240,yyyy: list<$2240>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2240,concat-preconcat-pre: forall<a> (ys : list<a>, zss : list<list<a>>) -> list<a>(yyyy: list<$2240>,zsszss: list<list<$2240>>))
      Nilstd/core/Nil: forall<a> list<a> -> match zsszss: list<list<$2240>>
        Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(zszs: list<$2240>,zzszzs: list<list<$2240>>) -> concat-preconcat-pre: forall<a> (ys : list<a>, zss : list<list<a>>) -> list<a>(zszs: list<$2240>,zzszzs: list<list<$2240>>)
        Nilstd/core/Nil: forall<a> list<a> -> Nilstd/core/Nil: forall<a> list<a>
  concat-preconcat-pre: forall<a> (ys : list<a>, zss : list<list<a>>) -> list<a>([std/core/Nil: forall<a> list<a>]std/core/Nil: forall<a> list<a>,xssxss: list<list<$2239>>)

// Concatenate the result lists from applying a function to all elements.
pub fun flatmapstd/core/flatmap: forall<a,b,e> (xs : list<a>, f : (a) -> e list<b>) -> e list<b>( xsxs: list<$2405>: liststd/core/list: V -> V<aa: V>, ff: ($2405) -> $2407 list<$2406> : aa: V -> ee: E liststd/core/list: V -> V<bb: V> ) : ee: E liststd/core/list: V -> V<bb: V>
  fun flatmap-preflatmap-pre: (list<$2406>, list<$2405>) -> $2407 list<$2406>( ysys: list<$2406>, zszs: list<$2405> )
    match ysys: list<$2406>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2406,yyyy: list<$2406>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2406,flatmap-preflatmap-pre: (list<$2406>, list<$2405>) -> $2407 list<$2406>(yyyy: list<$2406>,zszs: list<$2405>))
      Nilstd/core/Nil: forall<a> list<a> -> match zszs: list<$2405>
        Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(zz: $2405,zzzz: list<$2405>) -> flatmap-preflatmap-pre: (list<$2406>, list<$2405>) -> $2407 list<$2406>(ff: ($2405) -> $2407 list<$2406>(zz: $2405),zzzz: list<$2405>)
        Nilstd/core/Nil: forall<a> list<a> -> Nilstd/core/Nil: forall<a> list<a>
  flatmap-preflatmap-pre: (list<$2406>, list<$2405>) -> $2407 list<$2406>([std/core/Nil: forall<a> list<a>]std/core/Nil: forall<a> list<a>,xsxs: list<$2405>)

// Concatenate the `Just` result elements from applying a function to all elements.
pub fun flatmap-maybestd/core/flatmap-maybe: forall<a,b,e> (xs : list<a>, f : (a) -> e maybe<b>) -> e list<b>( xsxs: list<$12201> : liststd/core/list: V -> V<aa: V>, ff: ($12201) -> $12203 maybe<$12202> : aa: V -> ee: E maybestd/core/types/maybe: V -> V<bb: V> ) : ee: E liststd/core/list: V -> V<bb: V>
  match xsxs: list<$12201>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $12201,xxxx: list<$12201>) -> match ff: ($12201) -> $12203 maybe<$12202>(xx: $12201)
      Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $12202) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $12202, xxxx: list<$12201>.flatmap-maybestd/core/flatmap-maybe: forall<a,b,e> (xs : list<a>, f : (a) -> e maybe<b>) -> e list<b>(ff: ($12201) -> $12203 maybe<$12202>))
      Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<$12201>.flatmap-maybestd/core/flatmap-maybe: forall<a,b,e> (xs : list<a>, f : (a) -> e maybe<b>) -> e list<b>(ff: ($12201) -> $12203 maybe<$12202>)
    Nilstd/core/Nil: forall<a> list<a> -> Nilstd/core/Nil: forall<a> list<a>

// Concatenate a list of `:maybe` values
pub fun concat-maybestd/core/concat-maybe: forall<a> (xs : list<maybe<a>>) -> list<a>( xsxs: list<maybe<$10454>> : liststd/core/list: V -> V<maybestd/core/types/maybe: V -> V<aa: V>> ) : liststd/core/list: V -> V<aa: V>
  match xsxs: list<maybe<$10454>>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: maybe<$10454>,xxxx: list<maybe<$10454>>) -> match xx: maybe<$10454>
      Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $10454) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $10454, xxxx: list<maybe<$10454>>.concat-maybestd/core/concat-maybe: forall<a> (xs : list<maybe<a>>) -> list<a>)
      Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<maybe<$10454>>.concat-maybestd/core/concat-maybe: forall<a> (xs : list<maybe<a>>) -> list<a>
    Nilstd/core/Nil: forall<a> list<a> -> Nilstd/core/Nil: forall<a> list<a>

// Return the last element of a list (or `Nothing` for the empty list)
pub fun laststd/core/last: forall<a> (xs : list<a>) -> maybe<a>( xsxs: list<$13632> : liststd/core/list: V -> V<aa: V> ) : maybestd/core/types/maybe: V -> V<aa: V>
  match xsxs: list<$13632>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $13632,Nilstd/core/Nil: forall<a> list<a>) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $13632)
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,xxxx: list<$13632>)  -> laststd/core/last: forall<a> (xs : list<a>) -> maybe<a>(xxxx: list<$13632>)
    Nilstd/core/Nil: forall<a> list<a>         -> Nothingstd/core/types/Nothing: forall<a> maybe<a>

// Return the last element of a list (or `default` for the empty list)
pub fun laststd/core/last.1: forall<a> (xs : list<a>, default : a) -> a( xsxs: list<$13670> : liststd/core/list: V -> V<aa: V>, defaultdefault: $13670 : aa: V ) : astd/core/types/(<>): E
  match xsxs: list<$13670>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $13670,Nilstd/core/Nil: forall<a> list<a>) -> xx: $13670
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,xxxx: list<$13670>)  -> laststd/core/last.1: forall<a> (xs : list<a>, default : a) -> a(xxxx: list<$13670>,defaultdefault: $13670)
    Nilstd/core/Nil: forall<a> list<a>         -> defaultdefault: $13670

// Return the list without its last element.
// Return an empty list for an empty list.
pub fun initstd/core/init: forall<a> (xs : list<a>) -> list<a>( xsxs: list<$13096> : liststd/core/list: V -> V<aa: V> ) : liststd/core/list: V -> V<aa: V>
  match xsxs: list<$13096>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $13096, xxxx: list<$13096> as Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $13096,initstd/core/init: forall<a> (xs : list<a>) -> list<a>(xxxx: list<$13096>))
    _ -> Nilstd/core/Nil: forall<a> list<a>

// Get (zero-based) element `n`  of a list. Return a `:maybe` type.
pub fun [std/core/([]).2: forall<a> (xs : list<a>, n : int) -> maybe<a>]( xsxs: list<$9757> : liststd/core/list: V -> V<aa: V>, nn: int : intstd/core/types/int: V ) : maybestd/core/types/maybe: V -> V<aa: V>
  match xsxs: list<$9757>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $9757,xxxx: list<$9757>) -> if nn: int>std/core/(>).1: (x : int, y : int) -> bool0 then xxxx: list<$9757>[std/core/([]).2: forall<a> (xs : list<a>, n : int) -> maybe<a>nn: int -std/core/(-).4: (x : int, y : int) -> int 1]
                  elif nn: int==std/core/(==).1: (x : int, y : int) -> bool0 then Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $9757)
                  else Nothingstd/core/types/Nothing: forall<a> maybe<a>
    Nilstd/core/Nil: forall<a> list<a> -> Nothingstd/core/types/Nothing: forall<a> maybe<a>

// Do all elements satisfy a predicate ?
pub fun allstd/core/all: forall<a,e> (xs : list<a>, predicate : (a) -> e bool) -> e bool( xsxs: list<$9945> : liststd/core/list: V -> V<aa: V>, predicatepredicate: ($9945) -> $9946 bool : aa: V -> ee: E boolstd/core/types/bool: V ) : ee: E boolstd/core/types/bool: V
  match xsxs: list<$9945>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $9945,xxxx: list<$9945>) -> if predicatepredicate: ($9945) -> $9946 bool(xx: $9945) then xxxx: list<$9945>.allstd/core/all: forall<a,e> (xs : list<a>, predicate : (a) -> e bool) -> e bool(predicatepredicate: ($9945) -> $9946 bool) else Falsestd/core/types/False: bool
    Nilstd/core/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/any: forall<a,e> (xs : list<a>, predicate : (a) -> e bool) -> e bool( xsxs: list<$9973> : liststd/core/list: V -> V<aa: V>, predicatepredicate: ($9973) -> $9974 bool : aa: V -> ee: E boolstd/core/types/bool: V ) : ee: E boolstd/core/types/bool: V
  match xsxs: list<$9973>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $9973,xxxx: list<$9973>) -> if predicatepredicate: ($9973) -> $9974 bool(xx: $9973) then Truestd/core/types/True: bool else xxxx: list<$9973>.anystd/core/any: forall<a,e> (xs : list<a>, predicate : (a) -> e bool) -> e bool(predicatepredicate: ($9973) -> $9974 bool)
    Nilstd/core/Nil: forall<a> list<a> -> Falsestd/core/types/False: bool

// ----------------------------------------------------------------------------
// Characters
// ----------------------------------------------------------------------------

pub inline extern (==)std/core/(==): (char, char) -> bool : (charstd/core/types/char: V,charstd/core/types/char: V) -> boolstd/core/types/bool: V  
  inline "(#1 == #2)"
  js inline "(#1 === #2)" 

pub inline extern (!=)std/core/(!=): (char, char) -> bool : (charstd/core/types/char: V,charstd/core/types/char: V) -> boolstd/core/types/bool: V  
  inline "(#1 != #2)"
  js inline "(#1 !== #2)"

pub inline extern (<=)std/core/(<=): (char, char) -> bool : (charstd/core/types/char: V,charstd/core/types/char: V) -> boolstd/core/types/bool: V 
  inline "(#1 <= #2)"

pub inline extern (>=)std/core/(>=): (char, char) -> bool : (charstd/core/types/char: V,charstd/core/types/char: V) -> boolstd/core/types/bool: V 
  inline "(#1 >= #2)"

pub inline extern (<)std/core/(<): (char, char) -> bool  : (charstd/core/types/char: V,charstd/core/types/char: V) -> boolstd/core/types/bool: V 
  inline "(#1 < #2)"

pub inline extern (>)std/core/(>): (char, char) -> bool  : (charstd/core/types/char: V,charstd/core/types/char: V) -> boolstd/core/types/bool: V 
  inline "(#1 > #2)"

pub fun comparestd/core/compare.1: (x : char, y : char) -> order( xx: char : charstd/core/types/char: V, yy: char : charstd/core/types/char: V ) : orderstd/core/types/order: V
  if xx: char <std/core/(<): (char, char) -> bool yy: char then Ltstd/core/types/Lt: order
  elif xx: char >std/core/(>): (char, char) -> bool yy: char then Gtstd/core/types/Gt: order
  else Eqstd/core/types/Eq: order

// Convert a character to its unicode code point
pub inline extern intstd/core/int: (char) -> int : (charstd/core/types/char: V) -> intstd/core/types/int: V
  inline "#1"
  c "kk_integer_from_int"
  cs inline "new BigInteger(#1)"

// Convert a unicode code point to a character
pub inline extern charstd/core/char: (i : int) -> char( i : intstd/core/types/int: V) : charstd/core/types/char: V
  inline "(#1)"
  c "kk_integer_clamp32"
  cs inline "Primitive.IntToInt32(#1)"

// Add two character code points
pub fun (+)std/core/(+).3: (c : char, d : char) -> total char(cc: char : charstd/core/types/char: V, dd: char : charstd/core/types/char: V) : totalstd/core/total: E charstd/core/types/char: V 
  (cc: char.intstd/core/int: (char) -> int +std/core/(+).4: (x : int, y : int) -> int dd: char.intstd/core/int: (char) -> int).charstd/core/char: (i : int) -> char

// Substract two character codePoints
pub fun (-)std/core/(-).3: (c : char, d : char) -> total char(cc: char : charstd/core/types/char: V, dd: char : charstd/core/types/char: V) : totalstd/core/total: E charstd/core/types/char: V 
  (cc: char.intstd/core/int: (char) -> int -std/core/(-).4: (x : int, y : int) -> int dd: char.intstd/core/int: (char) -> int).charstd/core/char: (i : int) -> char

// Is the character a lower-case ASCII character ?
pub fun is-lowerstd/core/is-lower: (c : char) -> bool( cc: char : charstd/core/types/char: V ) : boolstd/core/types/bool: V 
  cc: char >=std/core/(>=): (char, char) -> bool 'a' &&std/core/types/(&&): (x : bool, y : bool) -> bool cc: char <=std/core/(<=): (char, char) -> bool 'z'

// Is the character an upper-case ASCII character ?
pub fun is-upperstd/core/is-upper: (c : char) -> bool( cc: char : charstd/core/types/char: V ) : boolstd/core/types/bool: V 
  cc: char >=std/core/(>=): (char, char) -> bool 'A' &&std/core/types/(&&): (x : bool, y : bool) -> bool cc: char <=std/core/(<=): (char, char) -> bool 'Z'

// Is the character an ASCII digit ?
pub fun is-digitstd/core/is-digit: (c : char) -> bool( cc: char : charstd/core/types/char: V ) : boolstd/core/types/bool: V 
  cc: char >=std/core/(>=): (char, char) -> bool '0' &&std/core/types/(&&): (x : bool, y : bool) -> bool cc: char <=std/core/(<=): (char, char) -> bool '9'

// Is the character an ASCII hexa-decimal digit ?
pub fun is-hex-digitstd/core/is-hex-digit: (c : char) -> bool( cc: char : charstd/core/types/char: V ) : boolstd/core/types/bool: V 
  cc: char.is-digitstd/core/is-digit: (c : char) -> bool ||std/core/types/(||): (x : bool, y : bool) -> bool (cc: char >=std/core/(>=): (char, char) -> bool 'a' &&std/core/types/(&&): (x : bool, y : bool) -> bool cc: char <=std/core/(<=): (char, char) -> bool 'f') ||std/core/types/(||): (x : bool, y : bool) -> bool (cc: char >=std/core/(>=): (char, char) -> bool 'A'  &&std/core/types/(&&): (x : bool, y : bool) -> bool cc: char <=std/core/(<=): (char, char) -> bool 'F')

// Is the character an ASCII letter is-
pub fun is-alphastd/core/is-alpha: (c : char) -> bool( cc: char : charstd/core/types/char: V ) : boolstd/core/types/bool: V 
  cc: char.is-lowerstd/core/is-lower: (c : char) -> bool ||std/core/types/(||): (x : bool, y : bool) -> bool cc: char.is-upperstd/core/is-upper: (c : char) -> bool

// Is the character ASCII letter or digit?
pub fun is-alpha-numstd/core/is-alpha-num: (c : char) -> bool( cc: char : charstd/core/types/char: V ) : boolstd/core/types/bool: V 
  cc: char.is-alphastd/core/is-alpha: (c : char) -> bool ||std/core/types/(||): (x : bool, y : bool) -> bool cc: char.is-digitstd/core/is-digit: (c : char) -> bool

// Is the character an ASCII character, e.g. `c <= '\x7F'`  ?
pub fun is-asciistd/core/is-ascii: (c : char) -> bool( cc: char : charstd/core/types/char: V )     : boolstd/core/types/bool: V 
  cc: char <=std/core/(<=): (char, char) -> bool '\DEL'

// Is the character an ASCII control character, e.g. `c < ' '`  ?
pub fun is-controlstd/core/is-control: (c : char) -> bool( cc: char : charstd/core/types/char: V )   : boolstd/core/types/bool: V 
  cc: char <std/core/(<): (char, char) -> bool ' '

// Tests if a character is an element of `" \t\n\r"`
pub fun is-whitestd/core/is-white: (c : char) -> bool( cc: char : charstd/core/types/char: V )     : boolstd/core/types/bool: V 
  cc: char ==std/core/(==): (char, char) -> bool ' ' ||std/core/types/(||): (x : bool, y : bool) -> bool cc: char ==std/core/(==): (char, char) -> bool '\t' ||std/core/types/(||): (x : bool, y : bool) -> bool cc: char ==std/core/(==): (char, char) -> bool '\n' ||std/core/types/(||): (x : bool, y : bool) -> bool cc: char ==std/core/(==): (char, char) -> bool '\r'

// ----------------------------------------------------------------------------
// Booleans
// ----------------------------------------------------------------------------

pub fun (==)std/core/(==).5: (x : bool, y : bool) -> bool( xx: bool : boolstd/core/types/bool: V, yy: bool : boolstd/core/types/bool: V) : boolstd/core/types/bool: V 
  if xx: bool then yy: bool else !std/core/types/(!).1: (b : bool) -> boolyy: bool

pub fun (!=)std/core/(!=).5: (x : bool, y : bool) -> bool( xx: bool : boolstd/core/types/bool: V, yy: bool : boolstd/core/types/bool: V) : boolstd/core/types/bool: V 
  if xx: bool then !std/core/types/(!).1: (b : bool) -> boolyy: bool else yy: bool

pub fun (<)std/core/(<).6: (x : bool, y : bool) -> bool( xx: bool : boolstd/core/types/bool: V, yy: bool : boolstd/core/types/bool: V) : boolstd/core/types/bool: V  
  (!std/core/types/(!).1: (b : bool) -> boolxx: bool &&std/core/types/(&&): (x : bool, y : bool) -> bool yy: bool)

pub fun (<=)std/core/(<=).6: (x : bool, y : bool) -> bool( xx: bool : boolstd/core/types/bool: V, yy: bool : boolstd/core/types/bool: V) : boolstd/core/types/bool: V 
  !std/core/types/(!).1: (b : bool) -> bool(xx: bool >std/core/(>).4: (x : bool, y : bool) -> bool yy: bool)

pub fun (>)std/core/(>).4: (x : bool, y : bool) -> bool( xx: bool : boolstd/core/types/bool: V, yy: bool : boolstd/core/types/bool: V) : boolstd/core/types/bool: V  
  (xx: bool &&std/core/types/(&&): (x : bool, y : bool) -> bool !std/core/types/(!).1: (b : bool) -> boolyy: bool)

pub fun (>=)std/core/(>=).5: (x : bool, y : bool) -> bool( xx: bool : boolstd/core/types/bool: V, yy: bool : boolstd/core/types/bool: V) : boolstd/core/types/bool: V 
  !std/core/types/(!).1: (b : bool) -> bool(xx: bool <std/core/(<).6: (x : bool, y : bool) -> bool yy: bool)

pub fun comparestd/core/compare.2: (x : bool, y : bool) -> order( xx: bool : boolstd/core/types/bool: V, yy: bool : boolstd/core/types/bool: V) : orderstd/core/types/order: V
  if xx: bool <std/core/(<).6: (x : bool, y : bool) -> bool yy: bool then Ltstd/core/types/Lt: order
  elif xx: bool >std/core/(>).4: (x : bool, y : bool) -> bool yy: bool then Gtstd/core/types/Gt: order
  else Eqstd/core/types/Eq: order

// Transform a boolean to a maybe type, using `Nothing` for `False`
pub fun maybestd/core/maybe.4: (b : bool) -> maybe<()>( bb: bool : boolstd/core/types/bool: V ) : maybestd/core/types/maybe: V -> V<(std/core/types/(): V)std/core/types/(): V>
  if bb: bool then Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>((std/core/types/(): ())std/core/types/(): ()) else Nothingstd/core/types/Nothing: forall<a> maybe<a>


// ----------------------------------------------------------------------------
// Integers
// ----------------------------------------------------------------------------

// Compare two integers
pub inline extern comparestd/core/compare: (x : int, y : int) -> order(^x : intstd/core/types/int: V, ^y : intstd/core/types/int: V) : orderstd/core/types/order: V
  c inline "kk_int_as_order(kk_integer_cmp_borrow(#1,#2,kk_context()),kk_context())"
  cs "Primitive.IntCompare"
  js "$std_core._int_compare"

// Are two integers equal?
pub inline extern (==)std/core/(==): (x : int, y : int) -> bool(^x : intstd/core/types/int: V, ^y : intstd/core/types/int: V) : boolstd/core/types/bool: V
  c  "kk_integer_eq_borrow"
  cs inline "(#1 == #2)"
  js "$std_core._int_eq"

// Are two integers not equal?
pub inline extern (!=)std/core/(!=): (x : int, y : int) -> bool(^x : intstd/core/types/int: V, ^y : intstd/core/types/int: V) : boolstd/core/types/bool: V
  c  "kk_integer_neq_borrow"
  cs inline "(#1 != #2)"
  js "$std_core._int_ne"

// Is the first integer smaller or equal to the second?
pub inline extern (<=)std/core/(<=): (x : int, y : int) -> bool(^x : intstd/core/types/int: V, ^y : intstd/core/types/int: V) : boolstd/core/types/bool: V
  c  "kk_integer_lte_borrow"
  cs inline "(#1 <= #2)"
  js "$std_core._int_le"

// Is the first integer greater or equal to the second?
pub inline extern (>=)std/core/(>=): (x : int, y : int) -> bool(^x : intstd/core/types/int: V, ^y : intstd/core/types/int: V) : boolstd/core/types/bool: V
  c  "kk_integer_gte_borrow"
  cs inline "(#1 >= #2)"
  js "$std_core._int_ge"

// Is the first integer smaller than the second?
pub inline extern (<)std/core/(<): (x : int, y : int) -> bool(^x : intstd/core/types/int: V, ^y : intstd/core/types/int: V) : boolstd/core/types/bool: V
  c  "kk_integer_lt_borrow"
  cs inline "(#1 < #2)"
  js "$std_core._int_lt"

// Is the first integer greater than the second?
pub inline extern (>)std/core/(>): (x : int, y : int) -> bool(^x : intstd/core/types/int: V, ^y : intstd/core/types/int: V) : boolstd/core/types/bool: V
  c  "kk_integer_gt_borrow"
  cs inline "(#1 > #2)"
  js "$std_core._int_gt"

inline extern int-addstd/core/int-add: (int, int) -> int : (intstd/core/types/int: V,intstd/core/types/int: V) -> intstd/core/types/int: V
  c  "kk_integer_add"
  cs inline "(#1 + #2)"
  js "$std_core._int_add"

// Add two integers.
pub fun (+)std/core/(+).4: (x : int, y : int) -> int(xx: int : intstd/core/types/int: V, yy: int : intstd/core/types/int: V ) : intstd/core/types/int: V 
  int-addstd/core/int-add: (int, int) -> int(xx: int,yy: int)

inline extern int-substd/core/int-sub: (int, int) -> int : (intstd/core/types/int: V,intstd/core/types/int: V) -> intstd/core/types/int: V
  c  "kk_integer_sub"
  cs inline "(#1 - #2)"
  js "$std_core._int_sub"

// Substract two integers.
pub fun (-)std/core/(-).4: (x : int, y : int) -> int(xx: int : intstd/core/types/int: V, yy: int : intstd/core/types/int: V ) : intstd/core/types/int: V 
  int-substd/core/int-sub: (int, int) -> int(xx: int,yy: int)

// Multiply two integers.
pub inline extern (*)std/core/(*): (int, int) -> int : (intstd/core/types/int: V,intstd/core/types/int: V) -> intstd/core/types/int: V
  c  "kk_integer_mul"
  cs inline "(#1 * #2)"
  js "$std_core._int_mul"

// Euclidean-0 division of two integers. See also `divmod:(x : int, y : int) -> (int,int)`.
pub inline extern (/)std/core/(/): (x : int, y : int) -> int(x:intstd/core/types/int: V,y:intstd/core/types/int: V) : intstd/core/types/int: V
  c  "kk_integer_div"
  cs "Primitive.IntDiv"
  js "$std_core._int_div"

// Euclidean modulus of two integers; always a non-negative number. See also `divmod:(x : int, y : int) -> (int,int)`.
pub inline extern (%)std/core/(%): (int, int) -> int  : (intstd/core/types/int: V,intstd/core/types/int: V) -> intstd/core/types/int: V
  c  "kk_integer_mod"
  cs "Primitive.IntMod"
  js "$std_core._int_mod"

// Euclidean-0 division & modulus.
// Euclidean division is defined as: For any `D`  and `d`  where `d!=0` , we have:
//
// 1. `D == d*(D/d) + (D%d)`
// 2. `D%d`  is always positive where `0 <= D%d < abs(d)`
//
// Moreover, Euclidean-0 is a total function, for the case where `d==0`  we have
// that `D%0 == D`  and `D/0 == 0` . So property (1) still holds, but not property (2).
//
// Useful laws that hold for Euclidean-0 division:
//
// * `D/(-d) == -(D/d)`
// * `D%(-d) == D%d`
// * `D/(2^n) == sar(D,n)         `  (with `0 <= n <= 31`  and `2^n`  means `2`  to the power of `n` )
// * `D%(2^n) == D & ((2^n) - 1)  `  (with `0 <= n <= 31`  and `2^n`  means `2`  to the power of `n` )
//
// See also _Division and modulus for computer scientists, Daan Leijen, 2001_ for further information
// available at: <http://research.microsoft.com/pubs/151917/divmodnote.pdf> .
pub inline extern divmodstd/core/divmod: (x : int, y : int) -> (int, int)(x:intstd/core/types/int: V,y:intstd/core/types/int: V) : (std/core/types/(,): (V, V) -> Vintstd/core/types/int: V,intstd/core/types/int: V)std/core/types/(,): (V, V) -> V
  c  "kk_integer_div_mod_tuple"
  cs "Primitive.IntDivMod"
  js "$std_core._int_divmod"

pub fun negatestd/core/negate: (i : int) -> int(ii: int : intstd/core/types/int: V) : intstd/core/types/int: V
  ~std/core/(~): (i : int) -> intii: int

// Negate an integer.
pub inline extern (~)std/core/(~): (i : int) -> int(i:intstd/core/types/int: V) : intstd/core/types/int: V
  c  "kk_integer_neg"
  cs inline "(-#1)"
  js "$std_core._int_negate"

// Convert an integer to a `:float64`. May return `nan` if the integer is too large to represent as a `:float64`.
pub inline extern float64std/core/float64: (i : int) -> float64( i : intstd/core/types/int: V) : float64std/core/types/float64: V
  c  "kk_integer_as_double"
  cs "Primitive.IntToDouble"
  js "$std_core._int_to_double"

// Convert an integer to a `:float32`. May return `nan` if the integer is too large to represent as a `:float32`.
pub inline extern float32std/core/float32: (i : int) -> float32( i : intstd/core/types/int: V) : float32std/core/types/float32: V
  c  "kk_integer_as_float"
  cs "Primitive.IntToFloat"
  js "$std_core._int_to_float"  

// Is this an odd integer?
pub inline extern is-oddstd/core/is-odd: (i : int) -> bool( i : intstd/core/types/int: V ) : boolstd/core/types/bool: V
  c  "kk_integer_is_odd"
  cs inline "!(#1.IsEven)"
  js "$std_core._int_isodd"

// Is this equal to zero?
pub inline extern is-zerostd/core/is-zero: (x : int) -> bool( ^x : intstd/core/types/int: V) : boolstd/core/types/bool: V
  c  inline "kk_integer_is_zero_borrow(#1)"
  cs inline "(#1.IsZero)"
  js "$std_core._int_iszero"

// Return the absolute value of an integer.
pub inline extern absstd/core/abs: (i : int) -> int(i : intstd/core/types/int: V) : intstd/core/types/int: V
  c  "kk_integer_abs"
  cs "BigInteger.Abs"
  js "$std_core._int_abs"

pub fun incstd/core/inc: (i : int) -> int( ii: int : intstd/core/types/int: V ) : intstd/core/types/int: V
  ii: int +std/core/(+).4: (x : int, y : int) -> int 1

pub fun decstd/core/dec: (i : int) -> int( ii: int : intstd/core/types/int: V ) : intstd/core/types/int: V
  ii: int -std/core/(-).4: (x : int, y : int) -> int 1

// Calculate `10^exp`
pub fun exp10std/core/exp10: (exp : int) -> int( expexp: int : intstd/core/types/int: V ) : intstd/core/types/int: V
  1.mul-exp10std/core/mul-exp10: (i : int, n : int) -> int(expexp: int)

// Raise an integer `i` to the power of `exp`.
pub extern powstd/core/pow: (i : int, exp : int) -> int( ii: int : intstd/core/types/int: V, expexp: int : intstd/core/types/int: V ) : intstd/core/types/int: V
  c  "kk_integer_pow"
  cs "Primitive.IntPow"
  js "_int_pow"

// Raise an integer `i` to the power of `exp`.
pub fun (^)std/core/(^).1: (i : int, exp : int) -> int(ii: int : intstd/core/types/int: V, expexp: int : intstd/core/types/int: V ) : intstd/core/types/int: V
  powstd/core/pow: (i : int, exp : int) -> int(ii: int,expexp: int)

// Calculate `2^exp`.
pub fun exp2std/core/exp2: (exp : int) -> int( expexp: int : intstd/core/types/int: V ) : intstd/core/types/int: V
  powstd/core/pow: (i : int, exp : int) -> int(2,expexp: int)

// Return the number of ending `0` digits of `i`. Return `0` when `i==0`.
pub extern is-exp10std/core/is-exp10: (i : int) -> int( ii: int : intstd/core/types/int: V ) : intstd/core/types/int: V
  c  "kk_integer_ctz"
  cs "Primitive.IntCountPow10"
  js "_int_count_pow10"

// Return the number of decimal digits of `i`. Return `0` when `i==0`.
pub extern count-digitsstd/core/count-digits: (i : int) -> int( ii: int : intstd/core/types/int: V ) : intstd/core/types/int: V
  c  "kk_integer_count_digits"
  cs "Primitive.IntCountDigits"
  js "_int_count_digits"

pub extern mul-exp10std/core/mul-exp10: (i : int, n : int) -> int( ii: int : intstd/core/types/int: V, nn: int : intstd/core/types/int: V ) : intstd/core/types/int: V
  c  "kk_integer_mul_pow10"
  cs "Primitive.IntMulPow10"
  js "_int_mul_pow10"

pub extern cdiv-exp10std/core/cdiv-exp10: (i : int, n : int) -> int( ii: int : intstd/core/types/int: V, nn: int : intstd/core/types/int: V ) : intstd/core/types/int: V
  c  "kk_integer_cdiv_pow10"
  cs "Primitive.IntCDivPow10"
  js "_int_cdiv_pow10"

pub fun cdivmod-exp10std/core/cdivmod-exp10: (i : int, n : int) -> (int, int)( ii: int : intstd/core/types/int: V, nn: int : intstd/core/types/int: V ) : (std/core/types/(,): (V, V) -> Vintstd/core/types/int: V,intstd/core/types/int: V)std/core/types/(,): (V, V) -> V
  if nn: int <=std/core/(<=).1: (x : int, y : int) -> bool 0 returnreturn: (int, int) (std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)ii: int,0)std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)
  val cqcq: int = ii: int.cdiv-exp10std/core/cdiv-exp10: (i : int, n : int) -> int(nn: int)
  val crcr: int = ii: int -std/core/(-).4: (x : int, y : int) -> int cqcq: int.mul-exp10std/core/mul-exp10: (i : int, n : int) -> int(nn: int)
  (std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)cqcq: int,crcr: int)std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)

pub fun divmod-exp10std/core/divmod-exp10: (i : int, n : int) -> (int, int)( ii: int : intstd/core/types/int: V, nn: int : intstd/core/types/int: V ) : (std/core/types/(,): (V, V) -> Vintstd/core/types/int: V,intstd/core/types/int: V)std/core/types/(,): (V, V) -> V
  val (std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)cqcq: int,crcr: int)std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b) = cdivmod-exp10std/core/cdivmod-exp10: (i : int, n : int) -> (int, int)(ii: int,nn: int)
  if !std/core/types/(!).1: (b : bool) -> boolcrcr: int.is-negstd/core/is-neg.2: (i : int) -> bool then (std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)cqcq: int,crcr: int)std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b) else (std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)cqcq: int.decstd/core/dec: (i : int) -> int, crcr: int +std/core/(+).4: (x : int, y : int) -> int exp10std/core/exp10: (exp : int) -> int(nn: int))std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)

// Is this an even integer?
pub fun is-evenstd/core/is-even: (i : int) -> bool(ii: int:intstd/core/types/int: V) : boolstd/core/types/bool: V 
  !std/core/types/(!).1: (b : bool) -> boolis-oddstd/core/is-odd: (i : int) -> bool(ii: int)

// Is the integer positive (stricly greater than zero)
pub fun is-posstd/core/is-pos.2: (i : int) -> bool(ii: int : intstd/core/types/int: V ) : boolstd/core/types/bool: V 
  ii: int.signstd/core/sign: (i : int) -> order ==std/core/(==).4: (x : order, y : order) -> bool Gtstd/core/types/Gt: order

// Is the integer negative (stricly smaller than zero)
pub fun is-negstd/core/is-neg.2: (i : int) -> bool(ii: int : intstd/core/types/int: V ) : boolstd/core/types/bool: V 
  ii: int.signstd/core/sign: (i : int) -> order ==std/core/(==).4: (x : order, y : order) -> bool Ltstd/core/types/Lt: order

pub inline extern signstd/core/sign: (i : int) -> order( ^i : intstd/core/types/int: V ) : orderstd/core/types/order: V
  c  inline "kk_int_as_order(kk_integer_signum_borrow(#1),kk_context())"
  cs "Primitive.IntSign"
  js "$std_core._int_sign"

// Return the minimum of two integers
pub fun minstd/core/min: (i : int, j : int) -> int( ii: int : intstd/core/types/int: V, jj: int : intstd/core/types/int: V ) : intstd/core/types/int: V 
  if ii: int <=std/core/(<=).1: (x : int, y : int) -> bool jj: int then ii: int else jj: int

// Return the maximum of two integers
pub fun maxstd/core/max: (i : int, j : int) -> int( ii: int : intstd/core/types/int: V, jj: int : intstd/core/types/int: V ) : intstd/core/types/int: V 
  if ii: int >=std/core/(>=).1: (x : int, y : int) -> bool jj: int then ii: int else jj: int

// Returns the smallest element of a list of integers (or `default` (=`0`) for the empty list)
pub fun minimumstd/core/minimum: (xs : list<int>, default : ?int) -> int( xsxs: list<int> : liststd/core/list: V -> V<intstd/core/types/int: V>, defaultdefault: ?int : intstd/core/types/optional: V -> V = 0 ) : intstd/core/types/int: V
  match xsxs: list<int>
    Nilstd/core/Nil: forall<a> list<a> -> defaultdefault: int
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: int,xxxx: list<int>) -> xxxx: list<int>.foldlstd/core/foldl: forall<a,b,e> (list<a>, b, (b, a) -> e b) -> e b( xx: int, minstd/core/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/maximum: (xs : list<int>, default : ?int) -> int( xsxs: list<int> : liststd/core/list: V -> V<intstd/core/types/int: V>, defaultdefault: ?int : intstd/core/types/optional: V -> V = 0 ) : intstd/core/types/int: V
  match xsxs: list<int>
    Nilstd/core/Nil: forall<a> list<a> -> defaultdefault: int
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: int,xxxx: list<int>) -> xxxx: list<int>.foldlstd/core/foldl: forall<a,b,e> (list<a>, b, (b, a) -> e b) -> e b( xx: int, maxstd/core/max: (i : int, j : int) -> int )

// Return the sum of a list of integers
pub fun sumstd/core/sum: (xs : list<int>) -> int( xsxs: list<int> : liststd/core/list: V -> V<intstd/core/types/int: V> ) : intstd/core/types/int: V
  xsxs: list<int>.foldlstd/core/foldl: forall<a,b,e> (list<a>, b, (b, a) -> e b) -> e b( 0, fn(xx: int,yy: int) { xx: int +std/core/(+).4: (x : int, y : int) -> int yy: int } )

// Transform an integer to a maybe type, using `Nothing` for `0`
pub fun maybestd/core/maybe.5: (i : int) -> maybe<int>( ii: int : intstd/core/types/int: V ) : maybestd/core/types/maybe: V -> V<intstd/core/types/int: V>
  if ii: int==std/core/(==).1: (x : int, y : int) -> bool0 then Nothingstd/core/types/Nothing: forall<a> maybe<a> else Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(ii: int)

// fold over the integers between [`start`,`end`] (inclusive).
pub fun fold-intstd/core/fold-int: forall<a,e> (start : int, end : int, init : a, f : (int, a) -> e a) -> e a( startstart: int : intstd/core/types/int: V, endend: int : intstd/core/types/int: V, initinit: $12251 : aa: V, ff: (int, $12251) -> $12252 $12251 : (intstd/core/types/int: V,aa: V) -> ee: E aa: V ) : ee: E aa: V
  if startstart: int >=std/core/(>=).1: (x : int, y : int) -> bool endend: int then initinit: $12251 else
    val xx: $12251 = ff: (int, $12251) -> $12252 $12251(startstart: int,initinit: $12251)
    fold-intstd/core/fold-int: forall<a,e> (start : int, end : int, init : a, f : (int, a) -> e a) -> e a(unsafe-decreasingstd/core/types/unsafe-decreasing: forall<a> (x : a) -> a(startstart: int.incstd/core/inc: (i : int) -> int), endend: int, xx: $12251, ff: (int, $12251) -> $12252 $12251)

// fold over the integers between [0,`upto`)  (not including `upto`).
pub fun fold-intstd/core/fold-int.1: forall<a,e> (upto : int, init : a, f : (int, a) -> e a) -> e a( uptoupto: int : intstd/core/types/int: V, initinit: $12307 : aa: V, ff: (int, $12307) -> $12308 $12307 : (intstd/core/types/int: V,aa: V) -> ee: E aa: V ) : ee: E aa: V
  fold-intstd/core/fold-int: forall<a,e> (start : int, end : int, init : a, f : (int, a) -> e a) -> e a( 0, uptoupto: int.decstd/core/dec: (i : int) -> int, initinit: $12307, ff: (int, $12307) -> $12308 $12307 )

// ----------------------------------------------------------------------------
// 32-bit integers
// Just define the operations needed for defining the std/core interface but
// don't export any definitions here. Full operations are defined in `std/int32`.
// ----------------------------------------------------------------------------

// Convert an `:int32` to an `:int`.
pub inline extern intstd/core/int: (i : int32) -> int( i : int32std/core/types/int32: V ) : intstd/core/types/int: V
  c  "kk_integer_from_int"
  cs inline "(new BigInteger(#1))"
  js "$std_core._int_from_int32"

// Convert an integer to an `:int32`. The number is _clamped_ to the maximal or minimum `:int32`
// value if it is outside the range of an `:int32`.
pub extern int32std/core/int32: (i : int) -> int32( ii: int : intstd/core/types/int: V) : int32std/core/types/int32: V
  c  "kk_integer_clamp32"
  cs "Primitive.IntToInt32"
  js "$std_core._int_clamp32"

// Convenient shorthand to `int32`, e.g. `1234.i32`
pub inline fun i32std/core/i32: (i : int) -> int32( ii: int : intstd/core/types/int: V ) : int32std/core/types/int32: V
  ii: int.int32std/core/int32: (i : int) -> int32



// Minimal set of operations that we need in `std/core`.
inline extern (<=)std/core/(<=): (int32, int32) -> bool : (int32std/core/types/int32: V,int32std/core/types/int32: V) -> boolstd/core/types/bool: V  
  inline "(#1 <= #2)"
  js inline "(#1 <= #2)"

inline extern (<)std/core/(<): (int32, int32) -> bool  : (int32std/core/types/int32: V,int32std/core/types/int32: V) -> boolstd/core/types/bool: V  
  inline "(#1 < #2)"
  js inline "(#1 < #2)"

inline extern (+)std/core/(+): (int32, int32) -> int32  : (int32std/core/types/int32: V,int32std/core/types/int32: V) -> int32std/core/types/int32: V 
  inline "(#1 + #2)"
  js inline "((#1 + #2)|0)"

inline extern (-)std/core/(-): (int32, int32) -> int32  : (int32std/core/types/int32: V,int32std/core/types/int32: V) -> int32std/core/types/int32: V 
  inline "(#1 - #2)"
  js inline "((#1 - #2)|0)"

inline extern is-posstd/core/is-pos: (i : int32) -> bool( i : int32std/core/types/int32: V ) : boolstd/core/types/bool: V 
  inline "(#1>0)"

inline extern is-negstd/core/is-neg: (i : int32) -> bool( i : int32std/core/types/int32: V ) : boolstd/core/types/bool: V 
  inline "(#1<0)"


fun incrstd/core/incr: (i : int32) -> int32( ii: int32 : int32std/core/types/int32: V ) : int32std/core/types/int32: V
  ii: int32 +std/core/(+): (int32, int32) -> int32 1.int32std/core/int32: (i : int) -> int32

fun decrstd/core/decr: (i : int32) -> int32( ii: int32 : int32std/core/types/int32: V ) : int32std/core/types/int32: V
  ii: int32 -std/core/(-): (int32, int32) -> int32 1.int32std/core/int32: (i : int) -> int32

// ----------------------------------------------------------------------------
// N-bit ssize_t
// Just define the operations needed for defining the std/core interface but
// don't export any definitions here.
// ----------------------------------------------------------------------------

// Convert an integer to an `:ssize_t`. The number is _clamped_ to the maximal or minimum `:ssize_t`
// value if it is outside the range of an `:ssize_t`.
pub extern ssize_tstd/core/ssize_t: (i : int) -> ssize_t( ii: int : intstd/core/types/int: V) : ssize_tstd/core/types/ssize_t: V
  c  "kk_integer_clamp_ssize_t" 
  cs "Primitive.IntToInt32"
  js "$std_core._int_clamp32"

// Convert an `:ssize_t` to an `:int`.
pub inline extern intstd/core/int: (i : ssize_t) -> int( i : ssize_tstd/core/types/ssize_t: V ) : intstd/core/types/int: V
  c  "kk_integer_from_ssize_t"
  cs inline "(new BigInteger(#1))"
  js "$std_core._int_from_int32"

// Minimal set of operations that we need in `std/core`.
inline extern (<=)std/core/(<=): (ssize_t, ssize_t) -> bool : (ssize_tstd/core/types/ssize_t: V,ssize_tstd/core/types/ssize_t: V) -> boolstd/core/types/bool: V   
  inline "(#1 <= #2)"

inline extern (>=)std/core/(>=): (ssize_t, ssize_t) -> bool : (ssize_tstd/core/types/ssize_t: V,ssize_tstd/core/types/ssize_t: V) -> boolstd/core/types/bool: V   
  inline "(#1 >= #2)"

inline extern (<)std/core/(<): (ssize_t, ssize_t) -> bool  : (ssize_tstd/core/types/ssize_t: V,ssize_tstd/core/types/ssize_t: V) -> boolstd/core/types/bool: V   
  inline "(#1 < #2)"

inline extern (+)std/core/(+): (ssize_t, ssize_t) -> ssize_t  : (ssize_tstd/core/types/ssize_t: V,ssize_tstd/core/types/ssize_t: V) -> ssize_tstd/core/types/ssize_t: V 
  inline "(#1 + #2)"
  js inline "((#1 + #2)|0)"

inline extern (-)std/core/(-): (ssize_t, ssize_t) -> ssize_t  : (ssize_tstd/core/types/ssize_t: V,ssize_tstd/core/types/ssize_t: V) -> ssize_tstd/core/types/ssize_t: V 
  inline "(#1 - #2)"
  js inline "((#1 - #2)|0)"

inline extern is-posstd/core/is-pos: (i : ssize_t) -> bool( i : ssize_tstd/core/types/ssize_t: V ) : boolstd/core/types/bool: V 
  inline "(#1 > 0)"

inline extern is-negstd/core/is-neg: (i : ssize_t) -> bool( i : ssize_tstd/core/types/ssize_t: V ) : boolstd/core/types/bool: V 
  inline "(#1 < 0)"

extern is-zerostd/core/is-zero.1: (i : ssize_t) -> bool( ii: ssize_t : ssize_tstd/core/types/ssize_t: V ) : boolstd/core/types/bool: V 
  inline "(#1 == 0)"
  js inline "(#1 === 0)"

extern decrstd/core/decr.1: (i : ssize_t) -> ssize_t(ii: ssize_t : ssize_tstd/core/types/ssize_t: V ) : ssize_tstd/core/types/ssize_t: V 
  inline "(#1 - 1)"

extern incrstd/core/incr.1: (i : ssize_t) -> ssize_t(ii: ssize_t : ssize_tstd/core/types/ssize_t: V ) : ssize_tstd/core/types/ssize_t: V 
  inline "(#1 + 1)"


// ----------------------------------------------------------------------------
// int8
// ----------------------------------------------------------------------------

// clamp an `:int` to fit in an `:int8`.
pub extern int8std/core/int8: (i : int) -> int8( ii: int : intstd/core/types/int: V) : int8std/core/types/int8: V
  c  "kk_integer_clamp_int8"
  cs "Primitive.IntToInt8"
  js "$std_core._int_clamp8"

// Convert an `:int8` to an `:int`.
pub inline extern intstd/core/int: (i : int8) -> int( i : int8std/core/types/int8: V ) : intstd/core/types/int: V
  c  "kk_integer_from_int8"
  cs inline "(new BigInteger(#1))"
  js "$std_core._int_from_int32"


// clamp an `:int` to fit in an `:int8` but interpret the `:int` as an unsigned 8-bit value,
// and clamp between 0 and 255.
pub extern uint8std/core/uint8: (i : int) -> int8( ii: int : intstd/core/types/int: V) : int8std/core/types/int8: V
  c  "kk_integer_clamp_byte"
  cs "Primitive.IntToUInt8"
  js "$std_core._int_clamp_byte"

// Convert an `:int8` to an `:int` but interpret the `:int8` as an unsigned 8-bit value between 0 and 255.
pub inline extern uintstd/core/uint: (i : int8) -> int( i : int8std/core/types/int8: V ) : intstd/core/types/int: V
  c  "kk_integer_from_uint8"
  cs inline "(new BigInteger(#1 >= 0 ? #1 : 256 + #1))"
  js "$std_core._int_from_int32"


// ----------------------------------------------------------------------------
// int16
// ----------------------------------------------------------------------------

// clamp an `:int` to fit in an `:int16`.
pub extern int16std/core/int16: (i : int) -> int16( ii: int : intstd/core/types/int: V) : int16std/core/types/int16: V
  c  "kk_integer_clamp_int16"
  cs "Primitive.IntToInt16"
  js "$std_core._int_clamp16"

// Convert an `:int16` to an `:int`.
pub inline extern intstd/core/int: (i : int16) -> int( i : int16std/core/types/int16: V ) : intstd/core/types/int: V 
  c  "kk_integer_from_int16"
  cs inline "(new BigInteger(#1))"
  js "$std_core._int_from_int32"


// ----------------------------------------------------------------------------
// int64
// ----------------------------------------------------------------------------

// clamp an `:int` to fit in an `:int64_t`.
pub extern int64std/core/int64: (i : int) -> int64( ii: int : intstd/core/types/int: V) : int64std/core/types/int64: V
  c  "kk_integer_clamp64"
  cs "Primitive.IntToInt64"
  js "$std_core._int_clamp64"

// Convert an `:int64_t` to an `:int`.
pub inline extern intstd/core/int: (i : int64) -> int( i : int64std/core/types/int64: V ) : intstd/core/types/int: V
  c  "kk_integer_from_int64"
  cs inline "(new BigInteger(#1))"
  js "$std_core._int_from_int64"

// Convenient shorthand to `int64`, e.g. `1234.i64`
pub inline fun i64std/core/i64: (i : int) -> int64( ii: int : intstd/core/types/int: V ) : int64std/core/types/int64: V
  ii: int.int64std/core/int64: (i : int) -> int64


// ----------------------------------------------------------------------------
// intptr_t
// ----------------------------------------------------------------------------

// clamp an `:int` to fit in an `:intptr_t`. 
pub extern intptr_tstd/core/intptr_t: (i : int) -> intptr_t( ii: int : intstd/core/types/int: V) : intptr_tstd/core/types/intptr_t: V
  c  "kk_integer_clamp_intptr_t"
  cs "Primitive.IntToInt64"
  js "$std_core._int_clamp64"

// Convert an `:intptr_t` to an `:int`.
pub inline extern intstd/core/int: (i : intptr_t) -> int( i : intptr_tstd/core/types/intptr_t: V ) : intstd/core/types/int: V
  c  "kk_integer_from_intptr_t"
  cs inline "(new BigInteger(#1))"
  js "$std_core._int_from_int64"



// ----------------------------------------------------------------------------
// Parse numbers
// ----------------------------------------------------------------------------

// Parse an integer using `parseInt`. If an illegal digit character is encountered the
// `default` value is returned. An empty string will also result in `default`.
pub fun parse-int-defaultstd/core/parse-int-default: (s : string, default : ?int, hex : ?bool) -> int( ss: string : stringstd/core/types/string: V, defaultdefault: ?int : intstd/core/types/optional: V -> V = 0, hexhex: ?bool : boolstd/core/types/optional: V -> V = Falsestd/core/types/False: bool ) : intstd/core/types/int: V
  if ss: string.is-emptystd/core/is-empty.2: (s : string) -> bool then defaultdefault: int else ss: string.parse-intstd/core/parse-int: (s : string, hex : ?bool) -> maybe<int>(hexhex: bool).maybestd/core/maybe.1: forall<a> (m : maybe<a>, nothing : a) -> a(defaultdefault: int)

// Parse an integer after trimming whitespace.
// If an illegal digit character is encountered `Nothing` is returned.
// An empty string will result in `Just(0)`.
// A string can start with a `-` sign for negative numbers,
// and with `0x` or `0X` for hexadecimal numbers (in which case the `hex` parameter is ignored).
pub fun parse-intstd/core/parse-int: (s : string, hex : ?bool) -> maybe<int>( ss: string : stringstd/core/types/string: V, hexhex: ?bool : boolstd/core/types/optional: V -> V = Falsestd/core/types/False: bool) : maybestd/core/types/maybe: V -> V<intstd/core/types/int: V>
  ss: string.trimstd/core/trim: (s : string) -> string.xparse-intstd/core/xparse-int: (s : string, hex : bool) -> maybe<int>(hexhex: bool)

extern xparse-intstd/core/xparse-int: (s : string, hex : bool) -> maybe<int>( ss: string : stringstd/core/types/string: V, hexhex: bool : boolstd/core/types/bool: V ) : maybestd/core/types/maybe: V -> V<intstd/core/types/int: V>
  c  "kk_integer_xparse"
  cs "Primitive.IntParse"
  js "_int_parse"

// ----------------------------------------------------------------------------
// Floating point
// todo: move to std/num/float64
// ----------------------------------------------------------------------------

pub inline extern (==)std/core/(==): (float64, float64) -> bool : (float64std/core/types/float64: V,float64std/core/types/float64: V) -> boolstd/core/types/bool: V  { inline "(#1 == #2)"; js inline "(#1 === #2)" }
pub inline extern (!=)std/core/(!=): (float64, float64) -> bool : (float64std/core/types/float64: V,float64std/core/types/float64: V) -> boolstd/core/types/bool: V  { inline "(#1 != #2)"; js inline "(#1 !== #2)" }
pub inline extern (<=)std/core/(<=): (float64, float64) -> bool : (float64std/core/types/float64: V,float64std/core/types/float64: V) -> boolstd/core/types/bool: V  { inline "(#1 <= #2)" }
pub inline extern (>=)std/core/(>=): (float64, float64) -> bool : (float64std/core/types/float64: V,float64std/core/types/float64: V) -> boolstd/core/types/bool: V  { inline "(#1 >= #2)" }
pub inline extern (<)std/core/(<): (float64, float64) -> bool  : (float64std/core/types/float64: V,float64std/core/types/float64: V) -> boolstd/core/types/bool: V  { inline "(#1 < #2)" }
pub inline extern (>)std/core/(>): (float64, float64) -> bool  : (float64std/core/types/float64: V,float64std/core/types/float64: V) -> boolstd/core/types/bool: V  { inline "(#1 > #2)" }
pub inline extern (+)std/core/(+): (float64, float64) -> float64 : (float64std/core/types/float64: V,float64std/core/types/float64: V) -> float64std/core/types/float64: V { inline "(#1 + #2)" }
pub inline extern (-)std/core/(-): (float64, float64) -> float64 : (float64std/core/types/float64: V,float64std/core/types/float64: V) -> float64std/core/types/float64: V { inline "(#1 - #2)" }
pub inline extern (*)std/core/(*): (float64, float64) -> float64 : (float64std/core/types/float64: V,float64std/core/types/float64: V) -> float64std/core/types/float64: V { inline "(#1 * #2)" }
pub inline extern (/)std/core/(/): (float64, float64) -> float64 : (float64std/core/types/float64: V,float64std/core/types/float64: V) -> float64std/core/types/float64: V { inline "(#1 / #2)" }
pub inline extern (%)std/core/(%): (float64, float64) -> float64 : (float64std/core/types/float64: V,float64std/core/types/float64: V) -> float64std/core/types/float64: V { c inline "fmod(#1,#2)"; inline "(#1 % #2)" }


// Is the value negative?
pub fun is-negstd/core/is-neg.3: (d : float64) -> bool( dd: float64 : float64std/core/types/float64: V ) : boolstd/core/types/bool: V
  dd: float64 <std/core/(<).4: (float64, float64) -> bool 0.0

// Is the value positive?
pub fun is-posstd/core/is-pos.3: (d : float64) -> bool( dd: float64 : float64std/core/types/float64: V ) : boolstd/core/types/bool: V
  dd: float64 >std/core/(>).2: (float64, float64) -> bool 0.0

// Is the value zero?
pub fun is-zerostd/core/is-zero.2: (d : float64) -> bool( dd: float64 : float64std/core/types/float64: V ) : boolstd/core/types/bool: V
  dd: float64 ==std/core/(==).2: (float64, float64) -> bool 0.0

pub fun signstd/core/sign.1: (d : float64) -> order( dd: float64 : float64std/core/types/float64: V ) : orderstd/core/types/order: V
  if dd: float64 <std/core/(<).4: (float64, float64) -> bool 0.0 then Ltstd/core/types/Lt: order elif dd: float64 >std/core/(>).2: (float64, float64) -> bool 0.0 then Gtstd/core/types/Gt: order else Eqstd/core/types/Eq: order

// Negate a `:float64`.
pub inline extern (~)std/core/(~): (f : float64) -> float64( f : float64std/core/types/float64: V ) : float64std/core/types/float64: V
  inline "(-#1)"  // inline so `~0.0` becomes negative zero

// convert a `:float64` to an `:int` using `round` to round to its nearest integer.
// (rounding to an even number on a tie)
// Returns `0` if the argument is not `finite?`.
pub inline extern intstd/core/int: (f : float64) -> int( f : float64std/core/types/float64: V ) : intstd/core/types/int: V
  c  "kk_integer_from_double"
  cs "Primitive.IntDouble"
  js "$std_core._int_double"

// Returns the value `f`  raised to the power `p` .
pub inline extern (^)std/core/(^): (f : float64, p : float64) -> float64( f : float64std/core/types/float64: V, p : float64std/core/types/float64: V) : float64std/core/types/float64: V
  c inline "pow(#1,#2)"
  cs "Math.Pow"
  js "Math.pow"

// Return the absolute value of a `:float64` `f`
pub inline extern absstd/core/abs: (f : float64) -> float64( f : float64std/core/types/float64: V ) : float64std/core/types/float64: V
  c inline "kk_double_abs(#1)"
  cs "Math.Abs"
  js "Math.abs"

// Returns the smallest of two floats
pub fun minstd/core/min.1: (x : float64, y : float64) -> float64( xx: float64 : float64std/core/types/float64: V, yy: float64 : float64std/core/types/float64: V ) : float64std/core/types/float64: V 
  if xx: float64 <=std/core/(<=).4: (float64, float64) -> bool yy: float64 then xx: float64 else yy: float64

// Returns the largest of two floats
pub fun maxstd/core/max.1: (x : float64, y : float64) -> float64( xx: float64 : float64std/core/types/float64: V, yy: float64 : float64std/core/types/float64: V ) : float64std/core/types/float64: V 
  if xx: float64 >=std/core/(>=).3: (float64, float64) -> bool yy: float64 then xx: float64 else yy: float64

// Returns the smallest element of a list of floats (or `0` for the empty list)
pub fun minimumstd/core/minimum.1: (xs : list<float64>) -> float64( xsxs: list<float64> : liststd/core/list: V -> V<float64std/core/types/float64: V> ) : float64std/core/types/float64: V
  match xsxs: list<float64>
    Nilstd/core/Nil: forall<a> list<a> -> 0.0
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: float64,xxxx: list<float64>) -> xxxx: list<float64>.foldlstd/core/foldl: forall<a,b,e> (list<a>, b, (b, a) -> e b) -> e b( xx: float64, minstd/core/min.1: (x : float64, y : float64) -> float64 )

// Returns the largest element of a list of floats (or `0` for the empty list)
pub fun maximumstd/core/maximum.1: (xs : list<float64>) -> float64( xsxs: list<float64> : liststd/core/list: V -> V<float64std/core/types/float64: V> ) : float64std/core/types/float64: V
  match xsxs: list<float64>
    Nilstd/core/Nil: forall<a> list<a> -> 0.0
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: float64,xxxx: list<float64>) -> xxxx: list<float64>.foldlstd/core/foldl: forall<a,b,e> (list<a>, b, (b, a) -> e b) -> e b( xx: float64, maxstd/core/max.1: (x : float64, y : float64) -> float64 )

// ----------------------------------------------------------------------------
// Strings
// ----------------------------------------------------------------------------

// A `:sslice` represents a sub-slice of string and
// has a specific start position and character count. It is used
// instead of string indices to make the actual internal representation
// of strings abstract (like UTF-8 or UTF-16). String slices are
// returned by functions that find sub strings or patterns in
// in strings. Use `string:(slice : sslice) -> string` to
// create a fresh substring from a slice.
abstract struct sslicestd/core/sslice: V( strstr: string : stringstd/core/types/string: V, startstart: ssize_t : ssize_tstd/core/types/ssize_t: V, lenlen: ssize_t : ssize_tstd/core/types/ssize_t: V )

// Internal export for the regex module
pub fun ".new-sslice"( strstr: string :stringstd/core/types/string: V, startstart: ssize_t: ssize_tstd/core/types/ssize_t: V, lenlen: ssize_t : ssize_tstd/core/types/ssize_t: V )
  Sslicestd/core/Sslice: (str : string, start : ssize_t, len : ssize_t) -> sslice(strstr: string,startstart: ssize_t,lenlen: ssize_t)

// Convert a character to a string
pub extern stringstd/core/string: (c : char) -> string : ( c : charstd/core/types/char: V ) -> stringstd/core/types/string: V
  c  "kk_string_from_char"
  cs inline "Primitive.CharToString(#1)"
  js inline "_char_to_string(#1)"

// Convert a vector of characters to a string.
pub extern stringstd/core/string.1: (vector<char>) -> string : (vectorstd/core/types/vector: V -> V<charstd/core/types/char: V>) -> stringstd/core/types/string: V
  c  "kk_string_from_chars"
  cs inline "Primitive.CharsToString(#1)"
  js inline "_chars_to_string(#1)"

// Convert a string to a vector of characters.
pub extern vectorstd/core/vector.1: (s : string) -> vector<char> : ( s : stringstd/core/types/string: V ) -> vectorstd/core/types/vector: V -> V<charstd/core/types/char: V>
  c  "kk_string_to_chars"
  cs inline "Primitive.StringToChars(#1)"
  js inline "_string_to_chars(#1)"

// Convert a string to a list of characters
pub extern liststd/core/list.6: (s : string) -> total list<char>( ss: string : stringstd/core/types/string: V ) : totalstd/core/total: E liststd/core/list: V -> V<charstd/core/types/char: V>
  c  "kk_string_to_list"
  cs inline "Primitive.StringToList(#1)"
  js inline "_string_to_list(#1)"

// Convert a list of characters to a string
pub extern stringstd/core/string.2: (cs : list<char>) -> total string( cscs: list<char> : liststd/core/list: V -> V<charstd/core/types/char: V> ) : totalstd/core/total: E stringstd/core/types/string: V
  c  "kk_string_from_list"
  cs inline "Primitive.ListToString(#1)"
  js inline "_list_to_string(#1)"

// Are two strings equal?
// Uses exact equality between character codes.
pub inline extern (==)std/core/(==): (string, string) -> bool : (stringstd/core/types/string: V,stringstd/core/types/string: V) -> boolstd/core/types/bool: V
  c  "kk_string_is_eq"
  cs inline "(#1 == #2)"
  js inline "(#1 === #2)"

// Are two strings not equal?
pub inline extern (!=)std/core/(!=): (string, string) -> bool : (stringstd/core/types/string: V,stringstd/core/types/string: V) -> boolstd/core/types/bool: V
  c  "kk_string_is_neq"
  inline "(#1 != #2)"
  js inline "(#1 !== #2)"

extern string-comparestd/core/string-compare: (x : string, y : string) -> int : ( x : stringstd/core/types/string: V, y : stringstd/core/types/string: V ) -> intstd/core/types/int: V
  c  "kk_string_cmp_int"
  cs inline "String.Compare(#1,#2)"
  js inline "(#1===#2 ? 0 : (#1 > #2 ? 1 : -1))"

// Compare two strings.
// Uses the character codes directly for comparison
pub fun comparestd/core/compare.3: (x : string, y : string) -> order( xx: string : stringstd/core/types/string: V, yy: string : stringstd/core/types/string: V) : orderstd/core/types/order: V
  string-comparestd/core/string-compare: (x : string, y : string) -> int(xx: string,yy: string).orderstd/core/order: (i : int) -> order

pub fun (>=)std/core/(>=).6: (x : string, y : string) -> bool( xx: string : stringstd/core/types/string: V, yy: string : stringstd/core/types/string: V ) : boolstd/core/types/bool: V { comparestd/core/compare.3: (x : string, y : string) -> order(xx: string,yy: string) >std/core/(>).3: (x : order, y : order) -> bool Ltstd/core/types/Lt: order }
pub fun (<=)std/core/(<=).7: (x : string, y : string) -> bool( xx: string : stringstd/core/types/string: V, yy: string : stringstd/core/types/string: V ) : boolstd/core/types/bool: V { comparestd/core/compare.3: (x : string, y : string) -> order(xx: string,yy: string) <std/core/(<).5: (x : order, y : order) -> bool Gtstd/core/types/Gt: order }
pub fun (>)std/core/(>).5: (x : string, y : string) -> bool( xx: string : stringstd/core/types/string: V, yy: string : stringstd/core/types/string: V ) : boolstd/core/types/bool: V  { comparestd/core/compare.3: (x : string, y : string) -> order(xx: string,yy: string) ==std/core/(==).4: (x : order, y : order) -> bool Gtstd/core/types/Gt: order }
pub fun (<)std/core/(<).7: (x : string, y : string) -> bool( xx: string : stringstd/core/types/string: V, yy: string : stringstd/core/types/string: V ) : boolstd/core/types/bool: V  { comparestd/core/compare.3: (x : string, y : string) -> order(xx: string,yy: string) ==std/core/(==).4: (x : order, y : order) -> bool Ltstd/core/types/Lt: order }

// Append two strings.
pub extern (++)std/core/(++).1: (x : string, y : string) -> string(xx: string : stringstd/core/types/string: V, yy: string : stringstd/core/types/string: V) : stringstd/core/types/string: V
  c "kk_string_cat"
  inline "(#1 + #2)"

// Choose a non-empty string