Skip to content

Instantly share code, notes, and snippets.

@ymdryo
Created February 7, 2024 08:29
Show Gist options
  • Save ymdryo/46438d2fe4c4c8fdafd08b6b1906f4ab to your computer and use it in GitHub Desktop.
Save ymdryo/46438d2fe4c4c8fdafd08b6b1906f4ab to your computer and use it in GitHub Desktop.
callCC ::
(MonadFreer c fr, Monad (fr f), c (FreerChurch f)) =>
(forall r. (a -> fr f r) -> fr f a) ->
fr f a
callCC f = reencodeFreer $ callCcChurch \exit -> reencodeFreer $ f (reencodeFreer . exit)
callCcChurch :: (forall r. (a -> FreerChurch f r) -> FreerChurch f a) -> FreerChurch f a
callCcChurch f = FreerChurch $ FT \k g -> runFT (unFreerChurch $ f $ pure . runIdentity . k) k g
getCC :: (MonadFreer c fr, Monad (fr f), c (FreerChurch f)) => fr f (fr f ())
getCC = callCC \exit -> let a = void $ exit a in pure a
reencodeFreer :: (Freer c fr, Freer c' fr', c (fr' f)) => fr f ~> fr' f
reencodeFreer = interpretFreer liftIns
@ymdryo
Copy link
Author

ymdryo commented Feb 7, 2024

FreerChurch: ChurchエンコードされたFreerの型
reencodeFreer: Freerのエンコーディングを別のものへ変換する
Freer c, MonadFreer: エンコーディングを捨象した一般のFreerを表現する型クラス

@ymdryo
Copy link
Author

ymdryo commented Feb 7, 2024

FTはfreeパッケージのもの

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment