queus

u/queus


r/KeybaseProofs•

Keybase proof

I am:

Proof:

hKRib2R5hqhkZXRhY2hlZMOpaGFzaF90eXBlCqNrZXnEIwEgLmjnC8S1kdhbTAzk6LXWF2ccsa6U3Typvj4t7ok2rzgKp3BheWxvYWTFAzl7ImJvZHkiOnsia2V5Ijp7ImVsZGVzdF9raWQiOiIwMTIwMmU2OGU3MGJjNGI1OTFkODViNGMwY2U0ZThiNWQ2MTc2NzFjYjFhZTk0ZGQzY2E5YmUzZTJkZWU4OTM2YWYzODBhIiwiaG9zdCI6ImtleWJhc2UuaW8iLCJraWQiOiIwMTIwMmU2OGU3MGJjNGI1OTFkODViNGMwY2U0ZThiNWQ2MTc2NzFjYjFhZTk0ZGQzY2E5YmUzZTJkZWU4OTM2YWYzODBhIiwidWlkIjoiZjgyNzA3NzNjYzIwYWRmZTlhMzE4ZDc1MjY0MDc2MTkiLCJ1c2VybmFtZSI6InZyb3RhcnUifSwibWVya2xlX3Jvb3QiOnsiY3RpbWUiOjE1MDE4Mjg2NDUsImhhc2giOiI2ZmM0YjU2NmMwOGY0MDJiY2IwNzAwNTl
10

r/ocaml•

So I'm sometimes tempted to replace it with match .. with .. when, but maybe this is a bit too much..

let best n m =
  let sn = sum_of_digits n in
  let sm = sum_of_digits m in
  match () with
  | _ when sn < sm -> m 
  | _ when sn > sm -> n
  | _ when n < m   -> n
  | _              -> m
420

r/ocaml•

Here is my example. It is about converting the a number to its English representation: 1002 -> one thousand two. And here is the relevant fragment of the code

and up_to_thousand n = upto 1000L 100L "hundred" up_to_million n
and up_to_million n  = upto 1000_000L 1000L "thousand" up_to_billion n
and up_to_billion n  = upto 1000_000_000L 1000_000L "million" up_to_trillion n
and up_to_trillion n = upto 1000_000_000_000L 1000_000_000L "billion" (fun _ -> assert false) n

and upto max factor word next = function (* more stuff *)

this works. But this

and up_to_thousand = upto 1000L 100L "hundred" up_to_million
and up_to_million  = upto 1000_000L 1000L "thousan
48

r/ocaml•

I had a bit of trouble with a type which I used for modeling trees, which can be navigated up, sideways and down, and where nodes can be added left, right and down. Context

I have the following type for nodes:

type node = {
  mutable value : int;
  parent : node option;
  left : node option;
  right : node option;
  mutable children : node list;
}

Pretty straightforward. Now suppose I need to find a node in the children list and do something like

if node = child then

then OCaml crashes with an out of memory error. Well, I guess that is what circular references and st

516