Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
* Rewrite PArr comprehension in Pugs.Eval into Seq operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyt committed Sep 24, 2011
1 parent 3a282b2 commit f855a44
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Pugs/src/Pugs/Eval.hs
Expand Up @@ -1181,14 +1181,18 @@ interpolateVal (VRef (MkRef (IHash hv))) = do
interpolateVal (VRef (MkRef (IPair pv))) = do
(k, v) <- pair_fetch pv
return [ Syn "named" [Val k, Val v] ]
interpolateVal (VV vv) | Just (CaptSub{ c_feeds = feeds } :: ValCapt) <- castVal vv = error "TODO"
{- return . F.toList $
[: Val (castV v) | v <- concatMapP f_positionals feeds :]
+:+ [: Syn "named" [Val (VStr $ cast k), Val (concatNamed v)] | (k, v) <- concatMapP (Seq.fromList . AtomMap.toList . f_nameds) feeds :]
where
concatNamed [:x:] = castV x
concatNamed xs = VList (F.toList (mapP castV xs)) -}
interpolateVal (VV vv)
| Just (CaptSub{ c_feeds = feeds } :: ValCapt) <- castVal vv
= let posPart = fmap (\v -> Val (castV v)) (concatMapSeq f_positionals feeds)
kvs = concatMapSeq (Seq.fromList . AtomMap.toList . f_nameds) feeds
namPart = fmap kvToExp kvs
in return (F.toList (posPart >< namPart))
interpolateVal val = return [Val val]
kvToExp (k, v) = Syn "named" [Val (VStr $ cast k), Val (concatNamed v)]
concatMapSeq f xs = F.foldr mappend mempty (fmap f xs)
concatNamed xs = case Seq.length xs of
1 -> castV (Seq.index xs 0)
_ -> VList (F.toList (fmap castV xs))

isInterpolated :: Exp -> Bool
isInterpolated (Ann _ exp) = isInterpolated exp
Expand Down

0 comments on commit f855a44

Please sign in to comment.