Last active
January 25, 2018 06:16
-
-
Save KeenS/f4399ad739012fa7886514f45d4af938 to your computer and use it in GitHub Desktop.
SMLでレンジリテラルっぽいの
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
| datatype range | |
| = to of int * int | |
| | below of int * int | |
| infix to below | |
| structure List = struct | |
| open List | |
| local | |
| fun fromRangeSub (cmp, x, y) = let | |
| fun loop (i, acc) = if cmp(i, y) | |
| then loop(i+1, i :: acc) | |
| else List.rev acc | |
| in | |
| loop (x, []) | |
| end | |
| in | |
| fun fromRange (x to y) = fromRangeSub(op<=, x, y) | |
| | fromRange (x below y) = fromRangeSub(op<, x, y) | |
| end | |
| end | |
| val list = List.fromRange(1 to 100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment