Skip to content

Commit

Permalink
PList traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
AriFordsham committed Aug 21, 2022
1 parent b4e64f5 commit 80556fe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Plutarch/CPS/Optics/Traversal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ ctraverseOf p = runCStar . p . CStar . (fmap . fmap . fmap) return

newtype FunList a b t = FunList {unFunList :: Either t (a, FunList a b (b -> t))}

single :: a -> FunList a b b
single a = FunList $ Right (a, FunList $ Left id)

instance Functor (FunList a b) where
fmap f (FunList (Left t)) = FunList (Left (f t))
fmap f (FunList (Right (a, as))) = FunList (Right (a, fmap (f .) as))
Expand Down
11 changes: 1 addition & 10 deletions Plutarch/Optics/PList.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ import Plutarch.CPS.Optics.Traversal
import Plutarch.Core
import Plutarch.PList

list' :: [a] -> Cont r (FunList a b [b])
list' [] = cont \f -> f (pure [])
list' (x : xs) = cont $ \c -> runCont (list' xs) (c . liftA2 (:) (single x))

single :: a -> FunList a b b
single a = FunList $ Right (a, FunList $ Left id)

list :: CTraversal r [a] [b] a b
list = traversal list'

plist'' ::
( ESOP edsl
, IsEType edsl a
Expand Down Expand Up @@ -71,3 +61,4 @@ plist ::
(Term edsl a)
(Term edsl b)
plist = traversal plist'

2 changes: 2 additions & 0 deletions Plutarch/PList.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ data PListF a self ef
= PNil
| PCons (ef /$ a) (ef /$ self)
deriving stock (Generic)
deriving anyclass EHasRepr

newtype PList a ef = PList {unPList :: ef /$ EFix (PListF a)}
deriving stock (Generic)
deriving anyclass EHasRepr

mkPList ::
( ESOP edsl
Expand Down

0 comments on commit 80556fe

Please sign in to comment.