Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / mlton / backend / scale.fun
1 (* Copyright (C) 2004-2007 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
3 *
4 * MLton is released under a BSD-style license.
5 * See the file MLton-LICENSE for details.
6 *)
7
8 functor Scale (S: SCALE_STRUCTS): SCALE =
9 struct
10
11 open S
12
13 datatype t = One | Two | Four | Eight
14
15 val toString =
16 fn One => "1"
17 | Two => "2"
18 | Four => "4"
19 | Eight => "8"
20
21 val layout = Layout.str o toString
22
23 val fromInt: int -> t option =
24 fn 1 => SOME One
25 | 2 => SOME Two
26 | 4 => SOME Four
27 | 8 => SOME Eight
28 | _ => NONE
29
30 val fromBytes: Bytes.t -> t option =
31 fromInt o Bytes.toInt
32
33 val toInt: t -> int =
34 fn One => 1
35 | Two => 2
36 | Four => 4
37 | Eight => 8
38
39 end