Skip to content

Instantly share code, notes, and snippets.

@smly
Created July 17, 2011 04:28
Show Gist options
  • Select an option

  • Save smly/1087181 to your computer and use it in GitHub Desktop.

Select an option

Save smly/1087181 to your computer and use it in GitHub Desktop.
ternary operator like expression
datatype 'a ternarylikeop = TrueExpression of 'a | FalseExpression
fun op ? (true, y) = TrueExpression y
| op ? (_, y) = FalseExpression
infix 6 ?;
fun op :- (TrueExpression x, _) = x
| op :- (FalseExpression, y) = y
infix 6 :-;
val test01 = (35 < 3) ? 2 :- 1;
val test02 = (35 > 3) ? 2 :- 1;
(*
- [opening /Users/smly/gitws/practice/smlnj/ternary_operation.sml]
datatype 'a ternarylikeop = FalseExpression | TrueExpression of 'a
val ? = fn : bool * 'a -> 'a ternarylikeop
infix 6 ?
val :- = fn : 'a ternarylikeop * 'a -> 'a
infix 6 :-
val test01 = 1 : int
val test02 = 2 : int
*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment