File tree Expand file tree Collapse file tree 3 files changed +99
-0
lines changed Expand file tree Collapse file tree 3 files changed +99
-0
lines changed Original file line number Diff line number Diff line change @@ -15,8 +15,10 @@ package fathom
1515-- modules to install
1616modules = Fathom
1717 , Fathom.Base
18+ , Fathom.Data.Bit
1819 , Fathom.Data.Sing
1920 , Fathom.Data.Refine
21+ , Fathom.Data.Word
2022 , Fathom.Closed.IndexedInductive
2123 , Fathom.Closed.InductiveRecursive
2224 , Fathom.Closed.InductiveRecursiveCustom
Original file line number Diff line number Diff line change 1+ ||| Binary digits
2+
3+ module Fathom.Data.Bit
4+
5+
6+ ||| A binary digit
7+ public export
8+ data Bit : Type where
9+ B0 : Bit
10+ B1 : Bit
11+
12+
13+ public export
14+ Cast Bit Bool where
15+ cast B0 = True
16+ cast B1 = False
17+
18+ public export
19+ Cast Bit Nat where
20+ cast B0 = 0
21+ cast B1 = 1
22+
23+ public export
24+ Cast Bit Int where
25+ cast B0 = 0
26+ cast B1 = 1
27+
28+ public export
29+ Cast Bit Integer where
30+ cast B0 = 0
31+ cast B1 = 1
32+
33+ public export
34+ Cast Bit Bits8 where
35+ cast B0 = 0
36+ cast B1 = 1
37+
38+ public export
39+ Cast Bit Bits16 where
40+ cast B0 = 0
41+ cast B1 = 1
42+
43+ public export
44+ Cast Bit Bits32 where
45+ cast B0 = 0
46+ cast B1 = 1
47+
48+ public export
49+ Cast Bit Bits64 where
50+ cast B0 = 0
51+ cast B1 = 1
52+
53+ public export
54+ Cast Bit Int8 where
55+ cast B0 = 0
56+ cast B1 = 1
57+
58+ public export
59+ Cast Bit Int16 where
60+ cast B0 = 0
61+ cast B1 = 1
62+
63+ public export
64+ Cast Bit Int32 where
65+ cast B0 = 0
66+ cast B1 = 1
67+
68+ public export
69+ Cast Bit Int64 where
70+ cast B0 = 0
71+ cast B1 = 1
Original file line number Diff line number Diff line change 1+ module Fathom.Data.Word
2+
3+
4+ import Data.Fin
5+
6+ import Fathom.Data.Bit
7+
8+
9+ ||| A binary word with a specified number of bits
10+ public export
11+ data Word : (0 size : Nat ) -> Type where
12+ Z : Word 0
13+ S : Bit -> {0 n : Nat } -> Word n -> Word (S n)
14+
15+
16+ export
17+ Cast (Word size) Nat where
18+ cast Z = 0
19+ cast (S B0 w) = cast w * 2
20+ cast (S B1 w) = S (cast w * 2 )
21+
22+ export
23+ Cast (Word size) Bits8 where
24+ cast Z = 0
25+ cast (S B0 w) = cast w * 2
26+ cast (S B1 w) = (cast w * 2 ) + 1
You can’t perform that action at this time.
0 commit comments