-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
85c16dc
commit 1dacc89
Showing
11 changed files
with
102 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Plutarch.Cont(pmatchCont) where | ||
|
||
import Control.Monad.Trans.Cont | ||
|
||
import Plutarch.Core | ||
|
||
pmatchCont :: | ||
( | ||
EConstructable edsl a, | ||
IsEType edsl r | ||
) => | ||
(EConcrete edsl a -> Cont (Term edsl r) b) -> | ||
Term edsl a -> | ||
Cont (Term edsl r) b | ||
pmatchCont cnt t = cont \c -> ematch t \con -> runCont (cnt con) c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,42 @@ | ||
{-# LANGUAGE PartialTypeSignatures #-} | ||
{-# OPTIONS_GHC -Wno-unused-top-binds #-} | ||
module Plutarch.Optics.Fix(fixt) where | ||
|
||
import Data.Fix | ||
import Control.Lens | ||
module Plutarch.Optics.Fix(pfix) where | ||
|
||
import Data.Functor.Base | ||
import Data.Function | ||
import Data.Profunctor | ||
|
||
fixt :: | ||
(Applicative f) => | ||
(forall ra rb. (ra -> f rb) -> a ra -> f (b rb)) -> | ||
Fix a -> | ||
f (Fix b) | ||
fixt f = fmap Fix . (fix (f . dimap unFix (fmap Fix))) . unFix | ||
import Control.Monad.Trans.Cont | ||
|
||
list' :: Traversal (Fix (ListF a)) (Fix (ListF b)) a b | ||
list' f = fixt (listf f) | ||
import Plutarch.Core | ||
import Plutarch.Cont | ||
|
||
listf :: | ||
(Applicative f) => | ||
(a -> f b) -> | ||
(ra -> f rb) -> | ||
ListF a ra -> | ||
f (ListF b rb) | ||
listf _ _ Nil = pure Nil | ||
listf f r (Cons a b) = Cons <$> f a <*> r b | ||
-- | Not a 'Plutarch.CPS.Optics.Traversal.CTraversal', but can be used to construct one. | ||
pfix :: | ||
( | ||
EConstructable edsl (EFix a), | ||
EConstructable edsl (a (EFix a)), | ||
EConstructable edsl (EFix b), | ||
EConstructable edsl (b (EFix b)), | ||
EConstructable edsl r, | ||
Applicative f | ||
) => | ||
( | ||
forall ra rb. | ||
( | ||
EConstructable edsl (a ra), | ||
EConstructable edsl (b rb) | ||
) => | ||
(Term edsl ra -> Cont (Term edsl r) (f (Term edsl rb ))) -> | ||
Term edsl (a ra ) -> Cont (Term edsl r) (f (Term edsl (b rb ))) | ||
) -> | ||
Term edsl (EFix a) -> Cont (Term edsl r) (f (Term edsl (EFix b))) | ||
pfix f = | ||
pmatchCont \(EFix a) -> | ||
fmap (econ . EFix) | ||
<$> fix | ||
(f . | ||
dimap | ||
(\fa -> ematch fa \(EFix a') -> a') | ||
(fmap (fmap (econ . EFix))) | ||
) | ||
a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,47 @@ | ||
module Plutarch.Optics.PList where | ||
|
||
import Control.Applicative | ||
import Control.Monad.Cont | ||
import Control.Monad.Trans.Cont | ||
import Plutarch.CPS.Optics.Traversal | ||
import Plutarch.Core | ||
import Plutarch.Cont | ||
import Plutarch.PList | ||
|
||
plist'' :: | ||
( ESOP edsl | ||
, IsEType edsl a | ||
, IsEType edsl b | ||
, IsEType edsl r | ||
, IsEType edsl (EFix (PListF a)) | ||
, EConstructable edsl (EFix (PListF a)) | ||
, IsEType edsl (EFix (PListF b)) | ||
, EConstructable edsl (EFix (PListF b)) | ||
) => | ||
Term edsl (EFix (PListF a)) -> | ||
Cont | ||
(Term edsl r) | ||
(FunList (Term edsl a) (Term edsl b) (Term edsl (EFix (PListF b)))) | ||
plist'' fl = cont \f -> | ||
ematch fl \(EFix l) -> ematch l \case | ||
PNil -> f . pure . econ . EFix . econ $ PNil | ||
PCons x xs -> | ||
runCont | ||
(plist'' xs) | ||
(f . liftA2 (\x' -> econ . EFix . econ . PCons x') (single x)) | ||
|
||
plist' :: | ||
( ESOP edsl | ||
, IsEType edsl a | ||
, IsEType edsl b | ||
, IsEType edsl r | ||
, IsEType edsl (EFix (PListF a)) | ||
, EConstructable edsl (EFix (PListF a)) | ||
, IsEType edsl (EFix (PListF b)) | ||
, EConstructable edsl (EFix (PListF b)) | ||
) => | ||
Term edsl (PList a) -> | ||
Cont | ||
(Term edsl r) | ||
(FunList (Term edsl a) (Term edsl b) (Term edsl (PList b))) | ||
plist' fl = fmap (econ . PList) <$> plist'' (ematch fl unPList) | ||
import Plutarch.Optics.Fix | ||
import Control.Applicative | ||
|
||
plist :: | ||
( ESOP edsl | ||
, IsEType edsl a | ||
, IsEType edsl b | ||
, IsEType edsl r | ||
, IsEType edsl (EFix (PListF a)) | ||
, EConstructable edsl (EFix (PListF a)) | ||
, IsEType edsl (EFix (PListF b)) | ||
, EConstructable edsl (EFix (PListF b)) | ||
, EConstructable edsl r | ||
) => | ||
CTraversal | ||
(Term edsl r) | ||
(Term edsl (PList a)) | ||
(Term edsl (PList b)) | ||
(Term edsl a) | ||
(Term edsl b) | ||
plist = traversal plist' | ||
plist = | ||
ctraversal | ||
\f -> pmatchCont (\(PList as) -> fmap (econ . PList) <$> plist' f as) | ||
|
||
plist' :: | ||
( | ||
EConstructable edsl (EFix (PListF a)), | ||
EConstructable edsl (PListF a (EFix (PListF a))), | ||
EConstructable edsl (EFix (PListF b)), | ||
EConstructable edsl r, | ||
EConstructable edsl (PListF b (EFix (PListF b))), | ||
Applicative f | ||
) => | ||
(Term edsl a -> f (Term edsl b)) -> | ||
Term edsl (EFix (PListF a)) -> | ||
Cont (Term edsl r) (f (Term edsl (EFix (PListF b)))) | ||
plist' f = | ||
pfix | ||
(\r -> pmatchCont \case | ||
PNil -> return $ pure (econ PNil) | ||
PCons a as -> fmap econ . liftA2 PCons (f a) <$> r as | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters