[Haskell-cafe] Re: Generalizing zip

Jón Fairbairn jon.fairbairn at cl.cam.ac.uk
Fri Nov 17 05:02:24 EST 2006


Jón Fairbairn <jon.fairbairn at cl.cam.ac.uk> writes:

> "Jason Dagit" <dagit at eecs.oregonstate.edu> writes:
> 
> > Well, this is basically just a zip with a special base case.  But you
> > [...]
> I wonder if there is mileage to be had from persuing
> something like this, rather different (off top of head, very
> provisional, E&OE &c) approach:
> 
>    extend_infinitely l = map Just l ++ repeat Nothing
>    promote1 rel (Just a) b = rel a b
>    promote1 rel Nothing b = False
>    is_pfx_of l1 l2 = and (zipWith (promote1 (==)) (extend_infinitely l2) l1)

or, possibly better 

   extend_infinitely l = map Just l ++ repeat Nothing
   is_pfx_of l1 l2 = and (zipWith (==) (extend_infinitely l2) (map Just l1))

-- 
Jón Fairbairn                                 Jon.Fairbairn at cl.cam.ac.uk




More information about the Haskell-Cafe mailing list