Skip to content

Instantly share code, notes, and snippets.

@gofer
Created August 26, 2014 17:33
Show Gist options
  • Save gofer/2d7a2c5a669fc1f98bcd to your computer and use it in GitHub Desktop.
Save gofer/2d7a2c5a669fc1f98bcd to your computer and use it in GitHub Desktop.
fun op ** (a, b) = let
val succ = fn x => x + 1
val pred = fn x => x - 1
val c = if a < b then succ a else pred a
in
if a = b then [a] else a::(op ** (c ,b))
end;
infix **;
fun op *** (a, b) = let
val succ = fn x => x + 1
val pred = fn x => x - 1
val c = if a < b then succ a else pred a
in
if a = b then [] else a::(op *** (c, b))
end;
infix ***;
1 ** 10;
(* val it = [1,2,3,4,5,6,7,8,9,10] : int list *)
1 *** 10;
(* val it = [1,2,3,4,5,6,7,8,9] : int list *)
3 ** ~3;
(* val it = [3,2,1,0,~1,~2,~3] : int list *)
~3 *** ~10;
(* val it = [~3,~4,~5,~6,~7,~8,~9] : int list *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment