Ignore:
Timestamp:
Sep 13, 2010, 11:04:55 AM (10 years ago)
Author:
mulligan
Message:

More work on bits, bytes, nibbles, and added modules for byte7s and
words.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Deliverables/D4.1/Bit.ml

    r62 r63  
    11(*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*)
    2 (* FILENAME: Bit.ml                                                          *)
     2(* FILENAME:    Bit.ml                                                       *)
    33(* DESCRIPTION: An ADT implementing bits, and common operations on them.     *)
    4 (* CREATED: 10/09/2010, Dominic Mulligan                                     *)
     4(* CREATED:     10/09/2010, Dominic Mulligan                                 *)
    55(* BUGS:                                                                     *)
    66(*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*^*)
     
    1212  val from_bool: bool -> bit
    1313  val from_int: int -> bit
     14  val from_string: string -> bit option
     15
     16  val to_bool: bit -> bool
     17  val to_int: bit -> int
     18  val to_string: bit -> string
    1419
    1520  val (-&-): bit -> bit -> bit
     
    1823  val not: bit -> bit
    1924
    20   val pretty: bit -> string
    2125end;;
    2226
     
    3135    else
    3236      false
     37  let from_string =
     38    function
     39      "0" -> Some false
     40    | "1" -> Some true
     41    | _ -> None
     42
     43  let to_int =
     44    function
     45      false -> 0
     46    | true -> 1
     47  let to_string l =
     48    match l with
     49      true -> "1"
     50    | false -> "0"
     51
     52  let to_bool b = b
    3353
    3454  let (-&-) l r =
     
    4868      true -> false
    4969    | false -> true
    50 
    51   let pretty l =
    52     match l with
    53       true -> "1b"
    54     | false -> "0b"
    5570end;;
Note: See TracChangeset for help on using the changeset viewer.