Last active
November 14, 2025 21:21
-
-
Save qexat/8d21b9824d643936b50c13fbe02df8c4 to your computer and use it in GitHub Desktop.
this is the future jane street wants. #NoToNil #protest #Option4Ever #foryou #foryoupage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type nil = Nil | |
| (* This version is unsafe because it makes the assumption that index >= 0. *) | |
| let rec get_unsafe : 'a. at:int -> from:'a list -> 'a | nil = | |
| fun ~at:index ~from:list -> | |
| match list with | |
| | [] -> Nil | |
| | first :: _ when index = 0 -> first | |
| | _ :: rest -> get_unsafe ~at:(index - 1) ~from:rest | |
| let rec get : 'a. at:int -> from:'a list -> 'a | nil = | |
| fun ~at:index ~from:list -> | |
| if index >= 0 | |
| then get_unsafe ~at:index ~from:list | |
| else get_unsafe ~at:(List.length list + index) ~from:list | |
| let get_exn : 'a. at:int -> from:'a list -> 'a = | |
| fun ~at ~from -> | |
| let value = get ~at ~from in | |
| match type of value with | |
| | nil -> failwith "get_exn: index out of bounds" | |
| | _ -> value |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To be clear, this is not valid OCaml code, it's just a (bad) proof of concept