Skip to content

Commit

Permalink
Add postulated IO bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
Cogsad authored and jespercockx committed Aug 7, 2023
1 parent 4a9a614 commit a42b630
Show file tree
Hide file tree
Showing 17 changed files with 124 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/Haskell/Law/Applicative.agda
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module Haskell.Law.Applicative where

open import Haskell.Law.Applicative.Def public
open import Haskell.Law.Applicative.Either public
open import Haskell.Law.Applicative.IO public
open import Haskell.Law.Applicative.List public
open import Haskell.Law.Applicative.Maybe public
12 changes: 12 additions & 0 deletions lib/Haskell/Law/Applicative/IO.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Haskell.Law.Applicative.IO where

open import Haskell.Prim
open import Haskell.Prim.IO

open import Haskell.Prim.Applicative

open import Haskell.Law.Applicative.Def

open import Haskell.Law.Functor.IO

instance postulate iLawfulApplicativeIO : IsLawfulApplicative IO
1 change: 1 addition & 0 deletions lib/Haskell/Law/Functor.agda
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module Haskell.Law.Functor where

open import Haskell.Law.Functor.Def public
open import Haskell.Law.Functor.Either public
open import Haskell.Law.Functor.IO public
open import Haskell.Law.Functor.List public
open import Haskell.Law.Functor.Maybe public
10 changes: 10 additions & 0 deletions lib/Haskell/Law/Functor/IO.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Haskell.Law.Functor.IO where

open import Haskell.Prim
open import Haskell.Prim.IO

open import Haskell.Prim.Functor

open import Haskell.Law.Functor.Def

instance postulate isLawFulFunctorIO : IsLawfulFunctor IO
1 change: 1 addition & 0 deletions lib/Haskell/Law/Monad.agda
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module Haskell.Law.Monad where

open import Haskell.Law.Monad.Def public
open import Haskell.Law.Monad.Either public
open import Haskell.Law.Monad.IO public
open import Haskell.Law.Monad.List public
open import Haskell.Law.Monad.Maybe public
12 changes: 12 additions & 0 deletions lib/Haskell/Law/Monad/IO.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module Haskell.Law.Monad.IO where

open import Haskell.Prim
open import Haskell.Prim.IO

open import Haskell.Prim.Monad

open import Haskell.Law.Monad.Def

open import Haskell.Law.Applicative.IO

instance postulate iLawfulMonadIO : IsLawfulMonad IO
1 change: 1 addition & 0 deletions lib/Haskell/Prelude.agda
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ open import Haskell.Prim.Foldable public
open import Haskell.Prim.Functor public
open import Haskell.Prim.Int public
open import Haskell.Prim.Integer public
open import Haskell.Prim.IO public
open import Haskell.Prim.List public
open import Haskell.Prim.Maybe public
open import Haskell.Prim.Monad public
Expand Down
3 changes: 3 additions & 0 deletions lib/Haskell/Prim/Applicative.agda
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ open import Haskell.Prim
open import Haskell.Prim.Either
open import Haskell.Prim.Foldable
open import Haskell.Prim.Functor
open import Haskell.Prim.IO
open import Haskell.Prim.List
open import Haskell.Prim.Maybe
open import Haskell.Prim.Monoid
Expand Down Expand Up @@ -85,3 +86,5 @@ instance
.pure x mempty ; mempty ; mempty ; x ; tt
._<*>_ (a ; b ; c ; f ; tt) (a₁ ; b₁ ; c₁ ; x ; tt)
a <> a₁ ; b <> b₁ ; c <> c₁ ; f x ; tt

instance postulate iApplicativeIO : Applicative IO
3 changes: 3 additions & 0 deletions lib/Haskell/Prim/Functor.agda
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Haskell.Prim.Functor where

open import Haskell.Prim
open import Haskell.Prim.Either
open import Haskell.Prim.IO
open import Haskell.Prim.List
open import Haskell.Prim.Maybe
open import Haskell.Prim.Tuple
Expand Down Expand Up @@ -77,3 +78,5 @@ instance

iFunctorTuple₄ : Functor (λ d Tuple (a ∷ b ∷ c ∷ d ∷ []))
iFunctorTuple₄ = fmap= λ f (x ; y ; z ; w ; tt) x ; y ; z ; f w ; tt

instance postulate iFunctiorIO : Functor IO
27 changes: 27 additions & 0 deletions lib/Haskell/Prim/IO.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Haskell.Prim.IO where

open import Haskell.Prim
open import Haskell.Prim.Show
open import Haskell.Prim.String

postulate IO : {a} Set a Set a

FilePath = String

postulate
-- Input functions
interact : (String String) IO ⊤
getContents : IO String
getLine : IO String
getChar : IO Char

-- Output functions
print : ⦃ Show a ⦄ a IO ⊤
putChar : Char IO ⊤
putStr : String IO ⊤
putStrLn : String IO ⊤

-- Files
readFile : FilePath IO String
writeFile : FilePath String IO ⊤
appendFile : FilePath String IO ⊤
3 changes: 3 additions & 0 deletions lib/Haskell/Prim/Monad.agda
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ open import Haskell.Prim.Applicative
open import Haskell.Prim.Either
open import Haskell.Prim.Foldable
open import Haskell.Prim.Functor
open import Haskell.Prim.IO
open import Haskell.Prim.List
open import Haskell.Prim.Maybe
open import Haskell.Prim.Monoid
Expand Down Expand Up @@ -97,6 +98,8 @@ instance
case k x of λ where
(a₁ ; b₁ ; c₁ ; y ; tt) a <> a₁ ; b <> b₁ ; c <> c₁ ; y ; tt

instance postulate iMonadIO : Monad IO

record MonadFail (m : Set Set) : Set₁ where
field
fail : String m a
Expand Down
4 changes: 4 additions & 0 deletions test/AllTests.agda
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ import TypeOperators
import ErasedTypeArguments
import TypeOperatorExport
import TypeOperatorImport
import IOFile
import IOInput

{-# FOREIGN AGDA2HS
import Issue14
Expand Down Expand Up @@ -110,4 +112,6 @@ import TypeOperators
import ErasedTypeArguments
import TypeOperatorExport
import TypeOperatorImport
import IOFile
import IOInput
#-}
13 changes: 13 additions & 0 deletions test/IOFile.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module IOFile where

open import Haskell.Prelude

main : IO ⊤
main = do file readFile "IOFile.agda"
writeFile "IOFile2.agda" file
appendFile "IOFile2.agda" "-- Written by appendFile"
file2 readFile "IOFile2.agda"
print file2
return tt

{-# COMPILE AGDA2HS main #-}
11 changes: 11 additions & 0 deletions test/IOInput.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module IOInput where

open import Haskell.Prelude

main : IO ⊤
main = do putStrLn "Write something "
x getLine
putStr $ "You wrote: " ++ x
return tt

{-# COMPILE AGDA2HS main #-}
2 changes: 2 additions & 0 deletions test/golden/AllTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ import TypeOperators
import ErasedTypeArguments
import TypeOperatorExport
import TypeOperatorImport
import IOFile
import IOInput

11 changes: 11 additions & 0 deletions test/golden/IOFile.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module IOFile where

main :: IO ()
main
= do file <- readFile "IOFile.agda"
writeFile "IOFile2.agda" file
appendFile "IOFile2.agda" "-- Written by appendFile"
file2 <- readFile "IOFile2.agda"
print file2
return ()

9 changes: 9 additions & 0 deletions test/golden/IOInput.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module IOInput where

main :: IO ()
main
= do putStrLn "Write something "
x <- getLine
putStr $ "You wrote: " ++ x
return ()

0 comments on commit a42b630

Please sign in to comment.