Skip to content

Commit 01239a6

Browse files
committed
[ new ] a type of bytes
1 parent a7ed49c commit 01239a6

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ New modules
177177
Data.Vec.Bounded.Show
178178
```
179179

180+
* A type of bytes:
181+
```agda
182+
Data.Word8.Primitive
183+
Data.Word8.Base
184+
Data.Word8.Literals
185+
```
186+
180187
Additions to existing modules
181188
-----------------------------
182189

GenerateEverything.hs

+3
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ sizedTypesModules = map modToFile
161161
, "Codata.Sized.Thunk"
162162
, "Data.Container.Fixpoints.Sized"
163163
, "Data.W.Sized"
164+
, "Data.Word8.Base"
165+
, "Data.Word8.Literals"
166+
, "Data.Word8.Primitive"
164167
, "Data.Nat.PseudoRandom.LCG.Unsafe"
165168
, "Data.Tree.Binary.Show"
166169
, "Data.Tree.Rose"

src/Data/Word8/Base.agda

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Bytes: base type and functions
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --cubical-compatible #-}
8+
9+
module Data.Word8.Base where
10+
11+
open import Agda.Builtin.Bool using (Bool)
12+
open import Agda.Builtin.Nat using (Nat; _==_)
13+
open import Agda.Builtin.String using (String)
14+
open import Agda.Builtin.Unit using (⊤)
15+
16+
------------------------------------------------------------------------------
17+
-- Re-export type and operations
18+
19+
open import Data.Word8.Primitive as Prim public
20+
using ( Word8
21+
; _+_)
22+
renaming ( fromNat to fromℕ
23+
; toNat to toℕ
24+
)
25+
26+
------------------------------------------------------------------------------
27+
-- Basic functions
28+
29+
_≡ᵇ_ : Word8 Word8 Bool
30+
w ≡ᵇ w′ = toℕ w == toℕ w′

src/Data/Word8/Literals.agda

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Byte Literals
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --cubical-compatible #-}
8+
9+
module Data.Word8.Literals where
10+
11+
open import Agda.Builtin.FromNat using (Number)
12+
open import Data.Unit.Base using (⊤)
13+
open import Data.Word8.Base using (Word8; fromℕ)
14+
15+
number : Number Word8
16+
number = record
17+
{ Constraint = λ _
18+
; fromNat = λ w fromℕ w
19+
}

src/Data/Word8/Primitive.agda

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
------------------------------------------------------------------------
2+
-- The Agda standard library
3+
--
4+
-- Bytes: simple bindings to Haskell types and functions
5+
------------------------------------------------------------------------
6+
7+
{-# OPTIONS --cubical-compatible #-}
8+
9+
module Data.Word8.Primitive where
10+
11+
open import Agda.Builtin.Nat using (Nat)
12+
13+
postulate
14+
Word8 : Set
15+
fromNat : Nat Word8
16+
toNat : Word8 Nat
17+
_+_ : Word8 Word8 Word8
18+
19+
{-# FOREIGN GHC import GHC.Word #-}
20+
21+
{-# COMPILE GHC Word8 = type Word8 #-}
22+
{-# COMPILE GHC fromNat = fromIntegral #-}
23+
{-# COMPILE GHC toNat = fromIntegral #-}
24+
{-# COMPILE GHC _+_ = (+) #-}

0 commit comments

Comments
 (0)