Skip to content

Commit

Permalink
head and connect
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjaguarpaw committed Feb 10, 2024
1 parent 2ca315d commit 2cdbb34
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion bluefin-internal/src/Bluefin/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import qualified Data.Unique
import GHC.Exts (Proxy#, proxy#)
import System.IO.Unsafe (unsafePerformIO)
import Unsafe.Coerce (unsafeCoerce)
import Prelude hiding (drop, read, return)
import Prelude hiding (drop, head, read, return)

type Effect = ()

Expand Down Expand Up @@ -674,3 +674,33 @@ countPositivesNegatives is = runEff $
"We saw a zero, but before that there were "
++ show p
++ " positives"

connect ::
(forall e1. Coroutine a b e1 -> Eff (e1 :& effs) r1) ->
(forall e2. a -> Coroutine b a e2 -> Eff (e2 :& effs) r2) ->
forall e1 e2.
(e1 :> effs, e2 :> effs) =>
Eff
effs
( Either
(r1, a -> Coroutine b a e2 -> Eff effs r2)
(r2, b -> Coroutine a b e1 -> Eff effs r1)
)
connect _ _ = error "connect unimplemented, sorry"

head' ::
forall a b r effs.
(forall e. Coroutine a b e -> Eff (e :& effs) r) ->
forall e.
(e :> effs) =>
Eff
effs
( Either
r
(a, b -> Coroutine a b e -> Eff effs r)
)
head' c = do
r <- connect c (\a _ -> pure a) @_ @effs
pure $ case r of
Right r' -> Right r'
Left (l, _) -> Left l

0 comments on commit 2cdbb34

Please sign in to comment.