@@ -406,8 +406,10 @@ module ErrorMonad {e} {E : Set e} where
406
406
catchError (fail e) h = h e
407
407
catchError (ok a) h = ok a
408
408
409
+ open import Category.Functor using (RawFunctor)
410
+ open import Category.Applicative using (RawApplicative)
409
411
410
- module IOMonad where
412
+ module IOFunctor where
411
413
open import IO.Primitive public using (return; _>>=_)
412
414
413
415
infixl 1 _>>_
@@ -420,6 +422,43 @@ module IOMonad where
420
422
_=<<_ : ∀ {a b} {A : Set a} {B : Set b} → (A → IO B) → IO A → IO B
421
423
k =<< m = m >>= k
422
424
425
+ -- The following definition is needed to create the RawFunctor instance.
426
+
427
+ infixl 4 _<$>_
428
+
429
+ _<$>_ : ∀ {a b} {A : Set a} {B : Set b} → (A → B) → IO A → IO B
430
+ f <$> m = m >>= λ a -> return (f a)
431
+
432
+ -- This module is needed to create the RawApplicative instance
433
+ -- in a way compatible with both std-lib v1.7.1/2 and v2.0.
434
+
435
+ module IOApplicative where
436
+ open IOFunctor public
437
+
438
+ rawFunctor : ∀ {ℓ} → RawFunctor (IO {a = ℓ})
439
+ rawFunctor = record { IOFunctor }
440
+
441
+ pure : ∀ {a} {A : Set a} → A → IO A
442
+ pure = return
443
+
444
+ infixl 4 _<*>_ _⊛_
445
+
446
+ _<*>_ : ∀ {a b} {A : Set a} {B : Set b} → IO (A → B) → IO A → IO B
447
+ mf <*> ma = mf >>= λ f → ma >>= λ a → return (f a)
448
+
449
+ _⊛_ : ∀ {a b} {A : Set a} {B : Set b} → IO (A → B) → IO A → IO B
450
+ _⊛_ = _<*>_
451
+
452
+ module IOMonad where
453
+ open IOApplicative public
454
+
455
+ -- Field rawApplicative is part of the RawMonad of std-lib v2.0
456
+ -- Thus we have to construct the Applicative implementation
457
+ -- even though we do not use it.
458
+ --
459
+ rawApplicative : ∀ {ℓ} → RawApplicative (IO {a = ℓ})
460
+ rawApplicative = record { IOApplicative }
461
+
423
462
{-# FOREIGN GHC import qualified Data.List #-}
424
463
{-# FOREIGN GHC import qualified Data.Text #-}
425
464
{-# FOREIGN GHC import qualified Data.Text.IO #-}
0 commit comments