Permalink
Browse files

some speculative, not-yet-working code for doing cool things with mat…

…ching/filtering over data structures

Ignore-this: 1ea7003c88e5f4fbb8d92b2f3197cb0e

darcs-hash:20110212221704-1e371-50a51b8c58de8d00e5e2666e713f1af943a2e0ea.gz
  • Loading branch information...
1 parent 1581895 commit fea821e69346f07b4a61ee6ac3bf0c765d98af98 Brent Yorgey committed Feb 12, 2011
Showing with 18 additions and 5 deletions.
  1. +14 −0 Data/Pattern/Base/Tuple.hs
  2. +4 −5 Data/Pattern/Common.hs
View
@@ -19,6 +19,8 @@ module Data.Pattern.Base.Tuple (
one,
(<>),
runTuple,
+ -- * Mapping and distributing over tuples
+ Map, Distribute(..)
) where
import Data.Pattern.Base.TypeList
@@ -52,3 +54,15 @@ one a = Tuple (mkOneD (\(Tuple' t) -> Tuple' (\k -> t (k a))))
runTuple :: Tuple xs -> Fun xs r -> r
runTuple (Tuple t) = runTuple' (evalD (Tuple' id) t)
+type family Map f xs
+type instance Map f Nil = Nil
+type instance Map f (h:*:t) = f h :*: Map f t
+
+class Distribute xs where
+ distribute :: Functor f => f (Tuple xs) -> Tuple (Map f xs)
+
+instance Distribute Nil where
+ distribute _ = zero
+
+instance Distribute t => Distribute (h :*: t) where
+ distribute f = undefined -- XXX
View
@@ -139,14 +139,13 @@ nil = is null
cons :: Pat2 a [a] [a]
cons = mk2 (\l -> case l of { (x:xs) -> Just (x,xs); _ -> Nothing })
-{-
-- XXX generalize this to traversable and so on (?)
+-- XXX fix description
-- | Matches lists which contain an element matching the given pattern.
-- (Note, to simply check whether a list contains a given element, you can use
--- @is (x `elem`)@.
-has :: Pat1 a [a]
-has = mk1 (\l -> find
--}
+-- @is (x `elem`)@.)
+-- filterp :: Pattern vs a -> Pattern (Map [] vs) [a]
+-- filterp (Pattern p) = Pattern $ \xs -> catMaybes (map p xs)
-- | \"0-tuple pattern\". A strict match on the @()@.
tup0 :: Pat0 ()

0 comments on commit fea821e

Please sign in to comment.