This file contains 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
(* 'b -> 'c) * ('a -> b') -> ('a -> 'c) *) | |
fun compose(f,g) = fn x => f(g x) | |
(* in ML you can compose functions like f o g *) | |
fun sqrt_of_abs1 i = Math.sqrt (Real.fromInt (abs i)) | |
val sqrt_of_abs2 = Math.sqrt o Real.fromInt o abs | |
(* we can also define our own infix operator to compose functions | |
the other way around *) | |
infix !> | |
fun x !> f = f x | |
fun sqrt_of_abs3 i = i !> abs !> Real.fromInt !> Math.sqrt | |
fun backup1 (f,g) = fn x => case f x of | |
NONE => g x | |
| SOME => y |
No comments:
Post a Comment