Skip to content

Instantly share code, notes, and snippets.

@lissahyacinth
Created December 20, 2018 14:49
Show Gist options
  • Save lissahyacinth/fca966d8302af3206ef8c05a55019f11 to your computer and use it in GitHub Desktop.
Save lissahyacinth/fca966d8302af3206ef8c05a55019f11 to your computer and use it in GitHub Desktop.
let reducable a b =
{code for aA reducing to nothing etc}
let rec solve a x =
if a.length = 0
then match x with
# a :: b indicates that x is being split into a - the head and b - the tail of the list.
# [] indicates an empty element
elem :: list_of_elems -> (solve elem list_of_elems)
# If there's nothing left in the list, just return the element.
| elem :: [] -> elem
else
match x with
elem :: list_of_elems -> (
match reducable a elem with
# There's no reduction, leave a in the list and work on the rest
(a, b) -> (a :: (solve b list_of_elems))
# There's a reduction to 0, so just let the upper function deal with it
| (a when a.length = 0 ) -> (solve '' x)
| elem :: None -> elem
# This is the end of the list, so only return the element we were using for comparison
| [] -> a
solve '' x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment