/*---------------------------------------------------------------------------
  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: _2286,yy: _2287)
  xx: _2286

// 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: (_2176) -> _2177 _2178,xx: _2176)
  ff: (_2176) -> _2177 _2178(xx: _2176)

// 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: (_2797) -> _2794 _2795,gg: (_2793) -> _2794 _2797)
  fn(xx: _2793) ff: (_2797) -> _2794 _2795(gg: (_2793) -> _2794 _2797(xx: _2793))

// The `ignore` function ignores its argument.
pub fun ignorestd/core/ignore: forall<a> (x : a) -> ()( xx: $2604 : 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: $2292 : aa: V ) : totalstd/core/total: E (( x : bb: V ) -> astd/core/types/(<>): E)
  fn(_) defaultdefault: $2292 

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

pub fun intstd/core/int.7: (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<$10098> : maybestd/core/types/maybe: V -> V<aa: V> ) : boolstd/core/types/bool: V
  match mm: maybe<$10098>
    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<$14432> : maybestd/core/types/maybe: V -> V<aa: V>, onNothingonNothing: $14433: bb: V, onJustonJust: ($14432) -> $14434 $14433: aa: V -> ee: E bb: V ) : ee: E bb: V
  match mm: maybe<$14432>
    Nothingstd/core/types/Nothing: forall<a> maybe<a> -> onNothingonNothing: $14433
    Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $14432) -> onJustonJust: ($14432) -> $14434 $14433(xx: $14432)

// 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<$14455> : maybestd/core/types/maybe: V -> V<aa: V>, nothingnothing: $14455 : aa: V ) : astd/core/types/(<>): E
  defaultstd/core/default: forall<a> (m : maybe<a>, nothing : a) -> a(mm: maybe<$14455>,nothingnothing: $14455)

// 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<$2330> : maybestd/core/types/maybe: V -> V<aa: V>, nothingnothing: $2330 : aa: V ) : astd/core/types/(<>): E
  match mm: maybe<$2330>
    Nothingstd/core/types/Nothing: forall<a> maybe<a> -> nothingnothing: $2330
    Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $2330) -> xx: $2330

// 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<$16542> : maybestd/core/types/maybe: V -> V<aa: V> ) : exnstd/core/exn: HX aa: V
  match mm: maybe<$16542>
    Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $16542) -> xx: $16542
    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<$5356> : maybestd/core/types/maybe: V -> V<aa: V>, ff: ($5356) -> $5358 $5357 : aa: V -> ee: E bb: V ) : ee: E maybestd/core/types/maybe: V -> V<bb: V>
  match mm: maybe<$5356>
    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: $5356) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(ff: ($5356) -> $5358 $5357(xx: $5356))

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

// 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<$14492,$14493> : eitherstd/core/types/either: (V, V) -> V<aa: V,bb: V> ) : maybestd/core/types/maybe: V -> V<bb: V>
  match ee: either<$14492,$14493>
    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: $14493) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $14493)

// 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<$5383,$5384> : eitherstd/core/types/either: (V, V) -> V<aa: V,bb: V>, ff: ($5384) -> $5386 $5385 : bb: V -> ee: E cc: V  ) : ee: E eitherstd/core/types/either: (V, V) -> V<aa: V,cc: V>
  match ee: either<$5383,$5384>
    Rightstd/core/types/Right: forall<a,b> (right : b) -> either<a,b>(xx: $5384) -> Rightstd/core/types/Right: forall<a,b> (right : b) -> either<a,b>(ff: ($5384) -> $5386 $5385(xx: $5384))
    Leftstd/core/types/Left: forall<a,b> (left : a) -> either<a,b>(xx: $5383)  -> Leftstd/core/types/Left: forall<a,b> (left : a) -> either<a,b>(xx: $5383)

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

// 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<$16200> : liststd/core/list: V -> V<aa: V> ) : liststd/core/list: V -> V<aa: V>
  match xsxs: list<$16200>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,xxxx: list<$16200>) -> xxxx: list<$16200>
    _          -> [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<$7612> : liststd/core/list: V -> V<aa: V> ) : boolstd/core/types/bool: V
  match xsxs: list<$7612>
    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.8: (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.8: (x : order) -> int ==std/core/(==).1: (x : int, y : int) -> bool yy: order.intstd/core/int.8: (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.8: (x : order) -> int !=std/core/(!=).1: (x : int, y : int) -> bool yy: order.intstd/core/int.8: (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.8: (x : order) -> int >=std/core/(>=).1: (x : int, y : int) -> bool yy: order.intstd/core/int.8: (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.8: (x : order) -> int <=std/core/(<=).1: (x : int, y : int) -> bool yy: order.intstd/core/int.8: (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.8: (x : order) -> int >std/core/(>).1: (x : int, y : int) -> bool yy: order.intstd/core/int.8: (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.8: (x : order) -> int <std/core/(<).1: (x : int, y : int) -> bool yy: order.intstd/core/int.8: (x : order) -> int
  
pub fun mapstd/core/map.2: forall<a,b,e> (t : (a, a), f : (a) -> e b) -> e (b, b)( tt: ($5421, $5421) : (std/core/types/(,): (V, V) -> Vaa: V,aa: V)std/core/types/(,): (V, V) -> V, ff: ($5421) -> $5423 $5422 : 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: ($5421, $5421).fststd/core/types/fst: forall<a,b> ((a, b)) -> a.ff: ($5421) -> $5423 $5422, tt: ($5421, $5421).sndstd/core/types/snd: forall<a,b> ((a, b)) -> b.ff: ($5421) -> $5423 $5422)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: ($5566, $5566, $5566) : (std/core/types/(,,): (V, V, V) -> Vaa: V,aa: V,aa: V)std/core/types/(,,): (V, V, V) -> V, ff: ($5566) -> $5568 $5567 : 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: ($5566, $5566, $5566).fststd/core/types/fst.1: forall<a,b,c> ((a, b, c)) -> a.ff: ($5566) -> $5568 $5567, tt: ($5566, $5566, $5566).sndstd/core/types/snd.1: forall<a,b,c> ((a, b, c)) -> b.ff: ($5566) -> $5568 $5567, tt: ($5566, $5566, $5566).thdstd/core/types/thd: forall<a,b,c> ((a, b, c)) -> c.ff: ($5566) -> $5568 $5567)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: ($5784, $5784, $5784, $5784) : (std/core/types/(,,,): (V, V, V, V) -> Vaa: V,aa: V,aa: V,aa: V)std/core/types/(,,,): (V, V, V, V) -> V, ff: ($5784) -> $5786 $5785 : 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: ($5784, $5784, $5784, $5784).fststd/core/types/fst.2: forall<a,b,c,d> ((a, b, c, d)) -> a.ff: ($5784) -> $5786 $5785, tt: ($5784, $5784, $5784, $5784).sndstd/core/types/snd.2: forall<a,b,c,d> ((a, b, c, d)) -> b.ff: ($5784) -> $5786 $5785, tt: ($5784, $5784, $5784, $5784).thdstd/core/types/thd.1: forall<a,b,c,d> ((a, b, c, d)) -> c.ff: ($5784) -> $5786 $5785, tt: ($5784, $5784, $5784, $5784).field4std/core/types/field4: forall<a,b,c,d> ((a, b, c, d)) -> d.ff: ($5784) -> $5786 $5785)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: _2934)
  [std/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>xx: _2934]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<_4477>)
  fun lenlen: forall<a> (list<a>, int) -> int(ysys: list<_4450>,accacc: int)
    match ysys: list<_4450>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,yyyy: list<_4450>) -> yyyy: list<_4450>.lenlen: (list<_4450>, int) -> int(accacc: int+std/core/(+).4: (x : int, y : int) -> int1)
      Nilstd/core/Nil: forall<a> list<a>        -> accacc: int
  xsxs: list<_4477>.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) -> $4885 $4884 : 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) -> $4885 $4884(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) -> $4885 $4884 ))
    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) -> $4995 $4994 : 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) -> $4995 $4994(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) -> $4995 $4994 ))
    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<$16757> : liststd/core/list: V -> V<aa: V>, ysys: list<$16758> : 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<$16757>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $16757,xxxx: list<$16757>) -> match ysys: list<$16758>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $16758,yyyy: list<$16758>) -> 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: $16757,yy: $16758)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<$16757>,yyyy: list<$16758>))
      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<$16800> : liststd/core/list: V -> V<aa: V>, ysys: list<$16801> :liststd/core/list: V -> V<bb: V>, ff: ($16800, $16801) -> $16803 $16802 : (aa: V,bb: V) -> ee: E cc: V ) : ee: E liststd/core/list: V -> V<cc: V>
  match xsxs: list<$16800>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $16800,xxxx: list<$16800>) -> match ysys: list<$16801>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $16801,yyyy: list<$16801>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: ($16800, $16801) -> $16803 $16802(xx: $16800,yy: $16801),zipwithstd/core/zipwith: forall<a,b,c,e> (xs : list<a>, ys : list<b>, f : (a, b) -> e c) -> e list<c>(xxxx: list<$16800>,yyyy: list<$16801>,ff: ($16800, $16801) -> $16803 $16802))
      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<$16848> : liststd/core/list: V -> V<aa: V>, ys0ys0: list<$16849> :liststd/core/list: V -> V<bb: V>, ff: (int, $16848, $16849) -> $16851 $16850 : (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<$16848>, list<$16849>) -> $16851 list<$16850>( ii: int, xsxs: list<$16848>, ysys: list<$16849> )
    match xsxs: list<$16848>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $16848,xxxx: list<$16848>) -> match ysys: list<$16849>
        Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $16849,yyyy: list<$16849>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (int, $16848, $16849) -> $16851 $16850(ii: int,xx: $16848,yy: $16849),zipwith-iterzipwith-iter: (int, list<$16848>, list<$16849>) -> $16851 list<$16850>(ii: int+std/core/(+).4: (x : int, y : int) -> int1,xxxx: list<$16848>,yyyy: list<$16849>))
        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<$16848>, list<$16849>) -> $16851 list<$16850>(0,xs0xs0: list<$16848>,ys0ys0: list<$16849>)

// 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<($16577, $16578)> : 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<(_16588, _16589)>, acc1acc1: list<_16588>, acc2acc2: list<_16589> )
    match ysys: list<(_16588, _16589)>
      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: _16588,yy: _16589)std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b),xxxx: list<(_16588, _16589)>) -> iteriter: (list<(_16588, _16589)>, list<_16588>, list<_16589>) -> (list<_16588>, list<_16589>)(xxxx: list<(_16588, _16589)>,Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: _16588,acc1acc1: list<_16588>),Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: _16589,acc2acc2: list<_16589>))
      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<_16588>),reversestd/core/reverse: forall<a> (xs : list<a>) -> list<a>(acc2acc2: list<_16589>))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<($16577, $16578)>,[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<$13780> : liststd/core/list: V -> V<aa: V>, nn: int : intstd/core/types/int: V ) : liststd/core/list: V -> V<aa: V>
  match xsxs: list<$13780>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $13780,xxxx: list<$13780>) | nn: int >std/core/(>).1: (x : int, y : int) -> bool 0 -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $13780, takestd/core/take: forall<a> (xs : list<a>, n : int) -> list<a>(xxxx: list<$13780>, 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<$11560> : liststd/core/list: V -> V<aa: V>, nn: int : intstd/core/types/int: V ) : liststd/core/list: V -> V<aa: V>
  match xsxs: list<$11560>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,xxxx: list<$11560>) | 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<$11560>, nn: int -std/core/(-).4: (x : int, y : int) -> int 1)
    _ -> xsxs: list<$11560>

// 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<$6071> : liststd/core/list: V -> V<aa: V>, ff: ($6071) -> $6073 $6072 : aa: V -> ee: E bb: V) : ee: E liststd/core/list: V -> V<bb: V>
  match xsxs: list<$6071>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $6071,xxxx: list<$6071>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: ($6071) -> $6073 $6072(xx: $6071), xxxx: list<$6071>.mapstd/core/map.5: forall<a,b,e> (xs : list<a>, f : (a) -> e b) -> e list<b>(ff: ($6071) -> $6073 $6072))
    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<$14179> : liststd/core/list: V -> V<aa: V>, ff: (idx : int, value : $14179) -> $14181 $14180 : (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<$14179>, int) -> $14181 list<$14180>(ysys: list<$14179>,ii: int)
    match ysys: list<$14179>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $14179,yyyy: list<$14179>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (idx : int, value : $14179) -> $14181 $14180(ii: int,yy: $14179), map-idxmap-idx: (list<$14179>, int) -> $14181 list<$14180>(yyyy: list<$14179>,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<$14179>, int) -> $14181 list<$14180>(xsxs: list<$14179>,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<$2717> : liststd/core/list: V -> V<aa: V>, ff: (value : $2717, rest : list<$2717>) -> $2719 $2718 : (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<$2717>) -> $2719 list<$2718>(ysys: list<$2717>)
    match ysys: list<$2717>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2717,yyyy: list<$2717>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (value : $2717, rest : list<$2717>) -> $2719 $2718(yy: $2717,yyyy: list<$2717>), yyyy: list<$2717>.mappeekmappeek: (list<$2717>) -> $2719 list<$2718>)
      Nilstd/core/Nil: forall<a> list<a> -> Nilstd/core/Nil: forall<a> list<a>
  mappeekmappeek: (list<$2717>) -> $2719 list<$2718>(xsxs: list<$2717>)

// 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<$14235> : liststd/core/list: V -> V<aa: V>, ff: (idx : int, value : $14235, rest : list<$14235>) -> $14237 $14236 : (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<$14235>, int) -> $14237 list<$14236>(ysys: list<$14235>,ii: int)
    match ysys: list<$14235>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $14235,yyyy: list<$14235>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(ff: (idx : int, value : $14235, rest : list<$14235>) -> $14237 $14236(ii: int,yy: $14235,yyyy: list<$14235>), mapidxmapidx: (list<$14235>, int) -> $14237 list<$14236>(yyyy: list<$14235>,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<$14235>, int) -> $14237 list<$14236>(xsxs: list<$14235>,0)

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

// Append two lists.
pub fun (++)std/core/(++): forall<a> (xs : list<a>, ys : list<a>) -> list<a>(xsxs: list<$3199> : liststd/core/list: V -> V<aa: V>, ysys: list<$3199> : 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<$3199>,ysys: list<$3199>)

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

// 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<_12442>,zz: _12438,ff: (_12442, _12438) -> _12440 _12438)
  xsxs: list<_12442>.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: _12438) fn(xx: _12438,yy: _12442) ff: (_12442, _12438) -> _12440 _12438(yy: _12442,xx: _12438)  

// 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<_12369>,zz: _12364,ff: (_12364, _12369) -> _12366 _12364)
  match xsxs: list<_12369>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: _12369,xxxx: list<_12369>) -> foldlstd/core/foldl: (list<_12369>, _12364, (_12364, _12369) -> _12366 _12364) -> _12366 _12364(xxxx: list<_12369>,ff: (_12364, _12369) -> _12366 _12364(zz: _12364,xx: _12369),ff: (_12364, _12369) -> _12366 _12364)
    Nilstd/core/Nil: forall<a> list<a>        -> zz: _12364

pub fun foldl1std/core/foldl1: forall<a,e> (xs : list<a>, f : (a, a) -> <exn|e> a) -> <exn|e> a(xsxs: list<$12392> : liststd/core/list: V -> V<aa: V>, ff: ($12392, $12392) -> <exn|$12393> $12392 : (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<$12392>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $12392,xxxx: list<$12392>) -> xxxx: list<$12392>.foldlstd/core/foldl: forall<a,b,e> (list<a>, b, (b, a) -> e b) -> e b(xx: $12392,ff: ($12392, $12392) -> <exn|$12393> $12392)
    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<$12460> : liststd/core/list: V -> V<aa: V>, ff: ($12460, $12460) -> <exn|$12461> $12460 : (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<$12460>.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: ($12460, $12460) -> <exn|$12461> $12460)

// Create a list of `n`  repeated elementes `x`
pub fun replicatestd/core/replicate: forall<a> (x : a, n : int) -> list<a>( xx: $15761 : 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: $15761, replicatestd/core/replicate: forall<a> (x : a, n : int) -> list<a>(xx: $15761,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<$13826> : 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<$13826>.takestd/core/take: forall<a> (xs : list<a>, n : int) -> list<a>(nn: int), xsxs: list<$13826>.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<$16119> : liststd/core/list: V -> V<aa: V>, predicatepredicate: ($16119) -> $16120 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<$16119>, list<$16119>) -> $16120 (list<$16119>, list<$16119>)( ysys: list<$16119>, accacc: list<$16119>)
    match ysys: list<$16119>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $16119,yyyy: list<$16119>) -> if yy: $16119.predicatepredicate: ($16119) -> $16120 bool then yyyy: list<$16119>.span-accspan-acc: (list<$16119>, list<$16119>) -> $16120 (list<$16119>, list<$16119>)(Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $16119,accacc: list<$16119>)) else (std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)accacc: list<$16119>.reversestd/core/reverse: forall<a> (xs : list<a>) -> list<a>,ysys: list<$16119>)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<$16119>.reversestd/core/reverse: forall<a> (xs : list<a>) -> list<a>, ysys: list<$16119>)std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)
  xsxs: list<$16119>.span-accspan-acc: (list<$16119>, list<$16119>) -> $16120 (list<$16119>, list<$16119>)( [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<$16255> : liststd/core/list: V -> V<aa: V>, predicatepredicate: ($16255) -> $16256 bool : aa: V -> ee: E boolstd/core/types/bool: V ) : ee: E liststd/core/list: V -> V<aa: V>
  match xsxs: list<$16255>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $16255,xxxx: list<$16255>) -> if xx: $16255.predicatepredicate: ($16255) -> $16256 bool then Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $16255, xxxx: list<$16255>.take-whilestd/core/take-while: forall<a,e> (xs : list<a>, predicate : (a) -> e bool) -> e list<a>(predicatepredicate: ($16255) -> $16256 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<$11601> : liststd/core/list: V -> V<aa: V>, predicatepredicate: ($11601) -> $11602 bool : aa: V -> ee: E boolstd/core/types/bool: V ) : ee: E liststd/core/list: V -> V<aa: V>
  match xsxs: list<$11601>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $11601,xxxx: list<$11601>) -> if xx: $11601.predicatepredicate: ($11601) -> $11602 bool then xxxx: list<$11601>.drop-whilestd/core/drop-while: forall<a,e> (xs : list<a>, predicate : (a) -> e bool) -> e list<a>(predicatepredicate: ($11601) -> $11602 bool) else xsxs: list<$11601>
    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<$11859> : liststd/core/list: V -> V<aa: V>, predpred: ($11859) -> $11860 bool : aa: V -> ee: E boolstd/core/types/bool: V ) : ee: E liststd/core/list: V -> V<aa: V>
  match xsxs: list<$11859>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $11859,xxxx: list<$11859>) -> if predpred: ($11859) -> $11860 bool(xx: $11859) then Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $11859,xxxx: list<$11859>.filterstd/core/filter: forall<a,e> (xs : list<a>, pred : (a) -> e bool) -> e list<a>(predpred: ($11859) -> $11860 bool)) else xxxx: list<$11859>.filterstd/core/filter: forall<a,e> (xs : list<a>, pred : (a) -> e bool) -> e list<a>(predpred: ($11859) -> $11860 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<$15703> : liststd/core/list: V -> V<aa: V>, predpred: ($15703) -> bool : aa: V -> boolstd/core/types/bool: V ) : liststd/core/list: V -> V<aa: V>
  xsxs: list<$15703>.filterstd/core/filter: forall<a,e> (xs : list<a>, pred : (a) -> e bool) -> e list<a>( fn(xx: $15703) !std/core/types/(!).1: (b : bool) -> boolpredpred: ($15703) -> bool(xx: $15703) )

// 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<$15668> : liststd/core/list: V -> V<aa: V>, predpred: ($15668) -> $15669 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<$15668>, predpred: ($15668) -> $15669 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<$15613> : liststd/core/list: V -> V<aa: V>, predpred: ($15613) -> $15614 bool : aa: V -> ee: E boolstd/core/types/bool: V, acc1acc1: list<$15613> : liststd/core/list: V -> V<aa: V>, acc2acc2: list<$15613> : 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<$15613>
    Nilstd/core/Nil: forall<a> list<a> -> (std/core/types/(,): forall<a,b> (fst : a, snd : b) -> (a, b)acc1acc1: list<$15613>.reversestd/core/reverse: forall<a> (xs : list<a>) -> list<a>, acc2acc2: list<$15613>.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: $15613,xxxx: list<$15613>) -> if (predpred: ($15613) -> $15614 bool(xx: $15613))
                    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<$15613>,predpred: ($15613) -> $15614 bool,Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $15613,acc1acc1: list<$15613>),acc2acc2: list<$15613>)
                    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<$15613>,predpred: ($15613) -> $15614 bool,acc1acc1: list<$15613>,Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $15613,acc2acc2: list<$15613>))

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

// Find the first element satisfying some predicate
pub fun findstd/core/find: forall<a> (xs : list<a>, pred : (a) -> bool) -> maybe<a>( xsxs: list<$11967> : liststd/core/list: V -> V<aa: V>, predpred: ($11967) -> bool : aa: V -> boolstd/core/types/bool: V ) : maybestd/core/types/maybe: V -> V<aa: V>
  xsxs: list<$11967>.foreach-whilestd/core/foreach-while: forall<a,b,e> (xs : list<a>, action : (a) -> e maybe<b>) -> e maybe<b> fn(xx: $11967)
    if predpred: ($11967) -> bool(xx: $11967) then Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $11967) 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<$12135> : liststd/core/list: V -> V<aa: V>, predpred: ($12135) -> maybe<$12136> : aa: V -> maybestd/core/types/maybe: V -> V<bb: V> ) : maybestd/core/types/maybe: V -> V<bb: V>
  xsxs: list<$12135>.foreach-whilestd/core/foreach-while: forall<a,b,e> (xs : list<a>, action : (a) -> e maybe<b>) -> e maybe<b>(predpred: ($12135) -> maybe<$12136>)

// 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<($13979, $13980)> : liststd/core/list: V -> V<(std/core/types/(,): (V, V) -> Vaa: V,bb: V)std/core/types/(,): (V, V) -> V>, predpred: ($13979) -> bool : aa: V -> boolstd/core/types/bool: V ) : maybestd/core/types/maybe: V -> V<bb: V>
  xsxs: list<($13979, $13980)>.foreach-whilestd/core/foreach-while: forall<a,b,e> (xs : list<a>, action : (a) -> e maybe<b>) -> e maybe<b> fn(kvkv: ($13979, $13980))
    if predpred: ($13979) -> bool(kvkv: ($13979, $13980).fststd/core/types/fst: forall<a,b> ((a, b)) -> a) then Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(kvkv: ($13979, $13980).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<$14542> : liststd/core/list: V -> V<aa: V> ) : maybestd/core/types/maybe: V -> V<aa: V>
  match xsxs: list<$14542>
    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: $14542,_) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $14542)

// Convert a `:maybe` type to a list type.
pub fun liststd/core/list.5: forall<a> (m : maybe<a>) -> list<a>( mm: maybe<$5318> : maybestd/core/types/maybe: V -> V<aa: V> ) : liststd/core/list: V -> V<aa: V>
  match mm: maybe<$5318>
    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: $5318) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $5318,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<$13032> : liststd/core/list: V -> V<aa: V>, predpred: ($13032) -> bool : aa: V -> boolstd/core/types/bool: V, idxidx: int : intstd/core/types/int: V ) : intstd/core/types/int: V
  match xsxs: list<$13032>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $13032,xxxx: list<$13032>) -> if predpred: ($13032) -> bool(xx: $13032) then idxidx: int else index-of-accstd/core/index-of-acc: forall<a> (xs : list<a>, pred : (a) -> bool, idx : int) -> int(xxxx: list<$13032>,predpred: ($13032) -> 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<$13071> : liststd/core/list: V -> V<aa: V>, predpred: ($13071) -> 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<$13071>, predpred: ($13071) -> 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<$11000> : liststd/core/list: V -> V<aa: V>, actionaction: ($11000) -> $11001 () : (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<$11000>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $11000,xxxx: list<$11000>) -> { actionaction: ($11000) -> $11001 ()(xx: $11000); xxxx: list<$11000>.foreachstd/core/foreach: forall<a,e> (xs : list<a>, action : (a) -> e ()) -> e ()(actionaction: ($11000) -> $11001 ()) }
    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<$10594> : liststd/core/list: V -> V<aa: V>, actionaction: ($10594) -> $10596 maybe<$10595> : (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<$10594>
    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: $10594,xxxx: list<$10594>) ->
      match actionaction: ($10594) -> $10596 maybe<$10595>(xx: $10594)
        Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<$10594>.foreach-whilestd/core/foreach-while: forall<a,b,e> (xs : list<a>, action : (a) -> e maybe<b>) -> e maybe<b>(actionaction: ($10594) -> $10596 maybe<$10595>)
        justjust: maybe<$10595>    -> justjust: maybe<$10595>      

// 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<$14292> : liststd/core/list: V -> V<aa: V>, actionaction: ($14292) -> $14294 maybe<$14293> : (aa: V) -> ee: E maybestd/core/types/maybe: V -> V<bb: V> ) : ee: E liststd/core/list: V -> V<bb: V>
  match xsxs: list<$14292>
    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: $14292,xxxx: list<$14292>) ->
      match actionaction: ($14292) -> $14294 maybe<$14293>(xx: $14292)
        Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $14293) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $14293,xxxx: list<$14292>.map-whilestd/core/map-while: forall<a,b,e> (xs : list<a>, action : (a) -> e maybe<b>) -> e list<b>(actionaction: ($14292) -> $14294 maybe<$14293>))
        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<$12565> : liststd/core/list: V -> V<aa: V>, actionaction: (int, $12565) -> $12566 () : (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<$12565>.foreachstd/core/foreach: forall<a,e> (xs : list<a>, action : (a) -> e ()) -> e () fn(xx: $12565)
    val jj: int = ii: int // don't dereference `i` inside the inject
    mask_1: H<localstd/core/types/local: H -> X>{ actionaction: (int, $12565) -> $12566 ()(jj: int,xx: $12565) }
    ii: local-var<$12570,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<$2616> : liststd/core/list: V -> V<aa: V>, sepsep: $2616 : aa: V ) : liststd/core/list: V -> V<aa: V>
  fun beforebefore: (list<$2616>) -> list<$2616>(ysys: list<$2616>)
    match ysys: list<$2616>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2616,yyyy: list<$2616>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(sepsep: $2616,Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2616,beforebefore: (list<$2616>) -> list<$2616>(yyyy: list<$2616>)))
      Nilstd/core/Nil: forall<a> list<a>        -> Nilstd/core/Nil: forall<a> list<a>
  match xsxs: list<$2616>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2616,xxxx: list<$2616>)  -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $2616, xxxx: list<$2616>.beforebefore: (list<$2616>) -> list<$2616>)
    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<$2234>> : 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<$2235> : liststd/core/list: V -> V<aa: V>, zsszss: list<list<$2235>> : liststd/core/list: V -> V<liststd/core/list: V -> V<aa: V>> ) : liststd/core/list: V -> V<aa: V>
    match ysys: list<$2235>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2235,yyyy: list<$2235>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2235,concat-preconcat-pre: forall<a> (ys : list<a>, zss : list<list<a>>) -> list<a>(yyyy: list<$2235>,zsszss: list<list<$2235>>))
      Nilstd/core/Nil: forall<a> list<a> -> match zsszss: list<list<$2235>>
        Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(zszs: list<$2235>,zzszzs: list<list<$2235>>) -> concat-preconcat-pre: forall<a> (ys : list<a>, zss : list<list<a>>) -> list<a>(zszs: list<$2235>,zzszzs: list<list<$2235>>)
        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<$2234>>)

// 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<$2400>: liststd/core/list: V -> V<aa: V>, ff: ($2400) -> $2402 list<$2401> : 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<$2401>, list<$2400>) -> $2402 list<$2401>( ysys: list<$2401>, zszs: list<$2400> )
    match ysys: list<$2401>
      Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2401,yyyy: list<$2401>) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $2401,flatmap-preflatmap-pre: (list<$2401>, list<$2400>) -> $2402 list<$2401>(yyyy: list<$2401>,zszs: list<$2400>))
      Nilstd/core/Nil: forall<a> list<a> -> match zszs: list<$2400>
        Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(zz: $2400,zzzz: list<$2400>) -> flatmap-preflatmap-pre: (list<$2401>, list<$2400>) -> $2402 list<$2401>(ff: ($2400) -> $2402 list<$2401>(zz: $2400),zzzz: list<$2400>)
        Nilstd/core/Nil: forall<a> list<a> -> Nilstd/core/Nil: forall<a> list<a>
  flatmap-preflatmap-pre: (list<$2401>, list<$2400>) -> $2402 list<$2401>([std/core/Nil: forall<a> list<a>]std/core/Nil: forall<a> list<a>,xsxs: list<$2400>)

// 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<$12200> : liststd/core/list: V -> V<aa: V>, ff: ($12200) -> $12202 maybe<$12201> : aa: V -> ee: E maybestd/core/types/maybe: V -> V<bb: V> ) : ee: E liststd/core/list: V -> V<bb: V>
  match xsxs: list<$12200>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $12200,xxxx: list<$12200>) -> match ff: ($12200) -> $12202 maybe<$12201>(xx: $12200)
      Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $12201) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $12201, xxxx: list<$12200>.flatmap-maybestd/core/flatmap-maybe: forall<a,b,e> (xs : list<a>, f : (a) -> e maybe<b>) -> e list<b>(ff: ($12200) -> $12202 maybe<$12201>))
      Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<$12200>.flatmap-maybestd/core/flatmap-maybe: forall<a,b,e> (xs : list<a>, f : (a) -> e maybe<b>) -> e list<b>(ff: ($12200) -> $12202 maybe<$12201>)
    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<$10453>> : liststd/core/list: V -> V<maybestd/core/types/maybe: V -> V<aa: V>> ) : liststd/core/list: V -> V<aa: V>
  match xsxs: list<maybe<$10453>>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: maybe<$10453>,xxxx: list<maybe<$10453>>) -> match xx: maybe<$10453>
      Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(yy: $10453) -> Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(yy: $10453, xxxx: list<maybe<$10453>>.concat-maybestd/core/concat-maybe: forall<a> (xs : list<maybe<a>>) -> list<a>)
      Nothingstd/core/types/Nothing: forall<a> maybe<a> -> xxxx: list<maybe<$10453>>.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<$13620> : liststd/core/list: V -> V<aa: V> ) : maybestd/core/types/maybe: V -> V<aa: V>
  match xsxs: list<$13620>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $13620,Nilstd/core/Nil: forall<a> list<a>) -> Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(xx: $13620)
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,xxxx: list<$13620>)  -> laststd/core/last: forall<a> (xs : list<a>) -> maybe<a>(xxxx: list<$13620>)
    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<$13658> : liststd/core/list: V -> V<aa: V>, defaultdefault: $13658 : aa: V ) : astd/core/types/(<>): E
  match xsxs: list<$13658>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $13658,Nilstd/core/Nil: forall<a> list<a>) -> xx: $13658
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(_,xxxx: list<$13658>)  -> laststd/core/last.1: forall<a> (xs : list<a>, default : a) -> a(xxxx: list<$13658>,defaultdefault: $13658)
    Nilstd/core/Nil: forall<a> list<a>         -> defaultdefault: $13658

// 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<$13084> : liststd/core/list: V -> V<aa: V> ) : liststd/core/list: V -> V<aa: V>
  match xsxs: list<$13084>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $13084, xxxx: list<$13084> 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: $13084,initstd/core/init: forall<a> (xs : list<a>) -> list<a>(xxxx: list<$13084>))
    _ -> 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<$9756> : 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<$9756>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $9756,xxxx: list<$9756>) -> if nn: int>std/core/(>).1: (x : int, y : int) -> bool0 then xxxx: list<$9756>[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: $9756)
                  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<$9944> : liststd/core/list: V -> V<aa: V>, predicatepredicate: ($9944) -> $9945 bool : aa: V -> ee: E boolstd/core/types/bool: V ) : ee: E boolstd/core/types/bool: V
  match xsxs: list<$9944>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $9944,xxxx: list<$9944>) -> if predicatepredicate: ($9944) -> $9945 bool(xx: $9944) then xxxx: list<$9944>.allstd/core/all: forall<a,e> (xs : list<a>, predicate : (a) -> e bool) -> e bool(predicatepredicate: ($9944) -> $9945 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<$9972> : liststd/core/list: V -> V<aa: V>, predicatepredicate: ($9972) -> $9973 bool : aa: V -> ee: E boolstd/core/types/bool: V ) : ee: E boolstd/core/types/bool: V
  match xsxs: list<$9972>
    Consstd/core/Cons: forall<a> (head : a, tail : list<a>) -> list<a>(xx: $9972,xxxx: list<$9972>) -> if predicatepredicate: ($9972) -> $9973 bool(xx: $9972) then Truestd/core/types/True: bool else xxxx: list<$9972>.anystd/core/any: forall<a,e> (xs : list<a>, predicate : (a) -> e bool) -> e bool(predicatepredicate: ($9972) -> $9973 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 `:double`. May return `nan` if the integer is too large to represent as a `:double`.
pub inline extern doublestd/core/double: (i : int) -> double( i : intstd/core/types/int: V) : doublestd/core/types/double: V
  c  "kk_integer_as_double"
  cs "Primitive.IntToDouble"
  js "$std_core._int_to_double"

// Is this an odd integer?
pub inline extern is-oddstd/core/is-odd: (int) -> bool   : ( 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: (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: $12250 : aa: V, ff: (int, $12250) -> $12251 $12250 : (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: $12250 else
    val xx: $12250 = ff: (int, $12250) -> $12251 $12250(startstart: int,initinit: $12250)
    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: $12250, ff: (int, $12250) -> $12251 $12250)

// 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: $12306 : aa: V, ff: (int, $12306) -> $12307 $12306 : (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: $12306, ff: (int, $12306) -> $12307 $12306 )

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

// 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)"


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

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

// ----------------------------------------------------------------------------
// Byte
// ----------------------------------------------------------------------------

// clamp an `:int` to fit in a `:byte`.
pub extern bytestd/core/byte: (i : int) -> byte( ii: int : intstd/core/types/int: V) : bytestd/core/types/byte: V
  c  "kk_integer_clamp_byte"
  cs inline "Primitive.IntToByte"
  js "$std_core._int_clamp_byte"

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

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

// ----------------------------------------------------------------------------
// Doubles 
// ----------------------------------------------------------------------------

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

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

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

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

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

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

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

// convert a `:double` 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: (d : double) -> int(d : doublestd/core/types/double: V ) : intstd/core/types/int: V
  c  "kk_integer_from_double"
  cs "Primitive.IntDouble"
  js "$std_core._int_double"

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

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

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

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

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

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

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