Line | |
---|
1 | (*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*) |
---|
2 | (* FILENAME: Word.ml *) |
---|
3 | (* DESCRIPTION: An ADT implementing standard 16 bit words, and common *) |
---|
4 | (* operations on them. *) |
---|
5 | (* CREATED: 13/09/2010, Dominic Mulligan *) |
---|
6 | (* BUGS: *) |
---|
7 | (*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*) |
---|
8 | |
---|
9 | open Bit;; |
---|
10 | open Nibble;; |
---|
11 | open Byte;; |
---|
12 | |
---|
13 | module type WORD = |
---|
14 | sig |
---|
15 | type bit |
---|
16 | type nibble |
---|
17 | type byte |
---|
18 | type word = private byte * byte |
---|
19 | |
---|
20 | val to_bits: word -> bit list |
---|
21 | |
---|
22 | val iter_bit: (bit -> string) -> word -> string |
---|
23 | |
---|
24 | val to_string: word -> string |
---|
25 | end;; |
---|
26 | |
---|
27 | module WordFunctor(Bit: BIT) |
---|
28 | (Nibble: NIBBLE |
---|
29 | with type bit = Bit.bit) |
---|
30 | (Byte: BYTE |
---|
31 | with type bit = Bit.bit |
---|
32 | and type nibble = Nibble.nibble): WORD |
---|
33 | with type bit = Bit.bit |
---|
34 | and type nibble = Nibble.nibble |
---|
35 | and type byte = Byte.byte = |
---|
36 | struct |
---|
37 | type bit = Bit.bit |
---|
38 | type nibble = Nibble.nibble |
---|
39 | type byte = Byte.byte |
---|
40 | type word = (byte * byte) |
---|
41 | |
---|
42 | let to_bits (b1, b2) = Byte.to_bits b1 @ Byte.to_bits b2 |
---|
43 | |
---|
44 | let iter_bit f w = foldr (^) "" (map f (to_bits w)) |
---|
45 | |
---|
46 | let to_string = iter_bit Bit.to_string |
---|
47 | end;; |
---|
48 | |
---|
49 | module Word = WordFunctor(Bit) (Nibble) (Byte);; |
---|
Note: See
TracBrowser
for help on using the repository browser.