Skip to content

Commit

Permalink
Add Bytes container (~= Haskell Bytestring)
Browse files Browse the repository at this point in the history
  • Loading branch information
phile314 committed Jul 23, 2016
1 parent 85aa57c commit 6214370
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Prelude.agda
Expand Up @@ -11,6 +11,7 @@ open import Prelude.String public
open import Prelude.Bool public
open import Prelude.Nat public
open import Prelude.Int public
open import Prelude.Bytes public
open import Prelude.Product public
open import Prelude.Sum public
open import Prelude.List public
Expand Down
45 changes: 45 additions & 0 deletions src/Prelude/Bytes.agda
@@ -0,0 +1,45 @@
module Prelude.Bytes where

open import Prelude.Bool
open import Prelude.Decidable
open import Prelude.Equality
open import Prelude.Equality.Unsafe

{-# IMPORT Data.ByteString #-}

postulate
Bytes : Set
{-# COMPILED_TYPE Bytes Data.ByteString.ByteString #-}


private
module Internal where
postulate
empty : Bytes
append : Bytes Bytes Bytes
{-# COMPILED empty Data.ByteString.empty #-}
{-# COMPILED append Data.ByteString.append #-}

-- Eq --

private
postulate eqBytes : Bytes Bytes Bool
{-# COMPILED eqBytes (==) #-}

decEqBytes : (x y : Bytes) Dec (x ≡ y)
decEqBytes x y with eqBytes x y
... | true = yes unsafeEqual
... | false = no unsafeNotEqual

instance
EqBytes : Eq Bytes
EqBytes = record { _==_ = decEqBytes }

-- Monoid --

instance
open import Prelude.Monoid
MonoidBytes : Monoid Bytes
MonoidBytes = record { mempty = Internal.empty; _<>_ = Internal.append }


1 change: 1 addition & 0 deletions src/Prelude/String.agda
Expand Up @@ -76,6 +76,7 @@ instance
IsString.Constraint ListIsString _ =
IsString.fromString ListIsString s = unpackString s

-- Monoid --

instance
open import Prelude.Monoid
Expand Down

0 comments on commit 6214370

Please sign in to comment.