<commit_before>define ["exports"], (libagda) ->

  fst = (x) -> x["proj₁"]
  snd = (x) -> x["proj₂"]

  id = (x) -> x
  libagda.id = id

  foldrArray = (a, nil, cons) ->
    len = a.length
    l = nil
    i = len - 1
    while i >= 0
      l = cons i, a[i], l
      i--
    l
  libagda.foldrArray = foldrArray

  fromList = (l0, fromElt) ->
    a = []
    i = 0
    go = (l) ->
      l
        "[]":  () -> { }
        "_∷_": (x, xs) ->
                  a[i] = fromElt x
                  i++
                  go xs
    go l0
    Object.freeze a
  libagda.fromList = (_A) -> (_B) -> (l) -> (fromElt) -> fromList l, fromElt

  objectFromList = (l0, key, val) ->
    o = {}
    go = (l) ->
      l
        "[]":  () -> { }
        "_∷_": (x, xs) ->
                o[key x] = val x
                go xs
    go l0
    Object.freeze o
  libagda.objectFromList = (_A) -> (l) -> (key) -> (val) -> objectFromList l, key, val

  fromValue = (v) ->
    v
      array:  (l) -> fromList l, fromValue
      object: (l) -> objectFromList l, fst, ((x) -> fromValue snd x)
      string: id
      number: id
      bool:   id
      null:   () -> null
  libagda.fromValue = fromValue

  libagda.readProp = (x) -> (y) ->
    z = x[y]
    if z
      z
    else
      throw "readProp(): undefined property #{y} for #{x}"

  tt   = (x) -> x.record()
  nil  = (l) -> l["[]"]()
  cons = (x, xs) -> (l) -> l["_∷_"](x, xs)
  libagda.tt = tt
  libagda.nil = nil
  libagda.cons = cons

  libagda.viewJSValue = (v) -> (w) ->
    switch typeof(v)
      when "array"  then w.array(v)
      when "object" then w.object(v)
      when "string" then w.string(v)
      when "number" then w.number(v)
      when "bool"   then w.bool(v)
      when "null"   then w.null()
      else throw "viewJSValue: IMPOSSIBLE"

  libagda.checkTypeof = (ty) -> (x) ->
    my = typeof x
    if my is ty
      x
    else
      throw "checkTypeof(): expected a #{ty} not a #{my}"

  libagda.decodeJSArray = (_A) -> (_B) -> (a) -> (f) ->
    foldrArray a, nil, (i,x,xs) -> cons ((f i) x), xs

  libagda.trace = (_A) -> (_B) -> (s) -> (a) -> (f) ->
    console.log "trace: #{s}#{a}";
    f a

  libagda.throw = (_A) -> (s) -> (_x) -> throw s

  libagda.assert = (b) -> (cb) -> throw "assert false" unless b; cb()

  libagda.process =
    exit: (code) -> (cb) -> process.exit code; cb()
    argv: (cb) -> cb(process.argv)

  # FFI.JS.Console.log : (msg : String) → JS!
  libagda.console =
    log: (s) -> (cb) -> console.log s; cb()

  libagda.StringToChar = (s) ->
    if s.length is 1
      s
    else
      throw "StringToChar: Expecting a string of length 1 not " + s.length

  libagda.substring  = (s) -> (i) -> (j) -> s.substring(i,j)<commit_msg>trace uses JSON.stringify to display the value now<commit_after>define ["exports"], (libagda) ->

  fst = (x) -> x["proj₁"]
  snd = (x) -> x["proj₂"]

  id = (x) -> x
  libagda.id = id

  foldrArray = (a, nil, cons) ->
    len = a.length
    l = nil
    i = len - 1
    while i >= 0
      l = cons i, a[i], l
      i--
    l
  libagda.foldrArray = foldrArray

  fromList = (l0, fromElt) ->
    a = []
    i = 0
    go = (l) ->
      l
        "[]":  () -> { }
        "_∷_": (x, xs) ->
                  a[i] = fromElt x
                  i++
                  go xs
    go l0
    Object.freeze a
  libagda.fromList = (_A) -> (_B) -> (l) -> (fromElt) -> fromList l, fromElt

  objectFromList = (l0, key, val) ->
    o = {}
    go = (l) ->
      l
        "[]":  () -> { }
        "_∷_": (x, xs) ->
                o[key x] = val x
                go xs
    go l0
    Object.freeze o
  libagda.objectFromList = (_A) -> (l) -> (key) -> (val) -> objectFromList l, key, val

  fromValue = (v) ->
    v
      array:  (l) -> fromList l, fromValue
      object: (l) -> objectFromList l, fst, ((x) -> fromValue snd x)
      string: id
      number: id
      bool:   id
      null:   () -> null
  libagda.fromValue = fromValue

  libagda.readProp = (x) -> (y) ->
    z = x[y]
    if z
      z
    else
      throw "readProp(): undefined property #{y} for #{x}"

  tt   = (x) -> x.record()
  nil  = (l) -> l["[]"]()
  cons = (x, xs) -> (l) -> l["_∷_"](x, xs)
  libagda.tt = tt
  libagda.nil = nil
  libagda.cons = cons

  libagda.viewJSValue = (v) -> (w) ->
    switch typeof(v)
      when "array"  then w.array(v)
      when "object" then w.object(v)
      when "string" then w.string(v)
      when "number" then w.number(v)
      when "bool"   then w.bool(v)
      when "null"   then w.null()
      else throw "viewJSValue: IMPOSSIBLE"

  libagda.checkTypeof = (ty) -> (x) ->
    my = typeof x
    if my is ty
      x
    else
      throw "checkTypeof(): expected a #{ty} not a #{my}"

  libagda.decodeJSArray = (_A) -> (_B) -> (a) -> (f) ->
    foldrArray a, nil, (i,x,xs) -> cons ((f i) x), xs

  libagda.trace = (_A) -> (_B) -> (s) -> (a) -> (f) ->
    console.log "trace: #{s}#{JSON.stringify(a) || a}";
    f a

  libagda.throw = (_A) -> (s) -> (_x) -> throw s

  libagda.assert = (b) -> (cb) -> throw "assert false" unless b; cb()

  libagda.process =
    exit: (code) -> (cb) -> process.exit code; cb()
    argv: (cb) -> cb(process.argv)

  # FFI.JS.Console.log : (msg : String) → JS!
  libagda.console =
    log: (s) -> (cb) -> console.log s; cb()

  libagda.StringToChar = (s) ->
    if s.length is 1
      s
    else
      throw "StringToChar: Expecting a string of length 1 not " + s.length

  libagda.substring  = (s) -> (i) -> (j) -> s.substring(i,j)
{'fraction_non_alphanumeric': 0.19185619955979458, 'fraction_numerical': 0.003301540719002201, 'mean_word_length': 1.745720040281974, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 125, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5472781', 'n_tokens_mistral': 2245, 'n_tokens_neox': 2165, 'n_words': 599}