Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Conversation

JanGe
Copy link
Member

@JanGe JanGe commented Jul 24, 2016

Issue #20

  • zip, zipWith, unzip
  • zip{2,7}, zipWith{2,7}, unzip{2,7}
  • Provide custom method definitions for Array, UArray and String with better performance
  • tests

@JanGe JanGe changed the title WIP Add Zipable type class with zip and zipWith methods [WIP][#20] Add Zipable type class with zip and zipWith methods Jul 24, 2016
| otherwise =
if predicate (unsafeIndex c i) then Just i else Nothing

instance C.Zipable (Array ty) where

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's spelt Zippable
https://en.wiktionary.org/wiki/zippable

@JanGe JanGe changed the title [WIP][#20] Add Zipable type class with zip and zipWith methods [WIP][#20] Add Zippable type class with zip and zipWith methods Jul 25, 2016
@JanGe
Copy link
Member Author

JanGe commented Jul 26, 2016

Damn it. GHC HEAD won't let me make String an instance of Zippable as zip can't be used with it:

Core/String/UTF8.hs:105:10: error:
• Couldn't match type ‘Char’ with ‘(C.Element a, C.Element b)’
  Inaccessible code in
    the type signature for:
      C.zip :: (C.Sequential a, C.Sequential b,
                C.Element String ~ (C.Element a, C.Element b)) =>
               a -> b -> String
• In the instance declaration for ‘C.Zippable String’

@JanGe JanGe changed the title [WIP][#20] Add Zippable type class with zip and zipWith methods [#20] Add Zippable type class with zip and zipWith methods Jul 27, 2016
@JanGe
Copy link
Member Author

JanGe commented Jul 27, 2016

For tuples sizes >= 3 I didn't implement a type specific zipWith so far. Are they needed?

JanGe added 7 commits July 27, 2016 23:52
Only works for boxed arrays and lists so far.
The type class essentially was building lazy list of values,
so calling a lazy `toList` on a collection also works and
makes this obsolete.
Apparently GHC HEAD can identify type class function that can
never be used in an instance of the type class because of type
constraints. E.g. `zip` can never be used with `String` as a
target collection. `zip` is no in another type class that
automatically has an instance for every `Sequential` collection
type that can store tuples.
@vincenthz
Copy link
Member

wow @JanGe. didn't have time to read it all yet, but this seems great ! Will try to process over the weekend

@JanGe
Copy link
Member Author

JanGe commented Jul 29, 2016

Well, actually the BoxedZippable type class doesn't work yet for tuples sizes >= 3.

$ zip3 (fromList "abc" :: String) (fromList "abc" :: String) (fromList "abc" :: String) :: Array (Char, Char, Char)

<interactive>:5:1:
    Couldn't match type ‘(Char, Char, Char)’
                   with ‘(Element String, Element String)’
    In the expression:
        zip3
          (fromList "abc" :: String)
          (fromList "abc" :: String)
          (fromList "abc" :: String) ::
          Array (Char, Char, Char)
    In an equation for ‘it’:
        it
          = zip3
              (fromList "abc" :: String)
              (fromList "abc" :: String)

(And GHC HEAD catches that at compile time!)

Still thinking about how I could best solve this...

Edit: Working now. My polymorphic BoxedZippable instance didn't work with bigger tuples anymore (obviously):

instance ( Sequential a, Sequential b
         , Zippable col, Element col ~ (Element a, Element b))
        => BoxedZippable col a b

Is there any way I could require Element col to support a boxed types?

JanGe added 3 commits July 29, 2016 12:12
Define single instances for boxed arrays and lists.
Move `unzip*` functions to `BoxedZippable` where they belong.
@vincenthz vincenthz merged commit cd68943 into haskell-foundation:master Aug 6, 2016
@vincenthz
Copy link
Member

Nice work. we can improve on the building side of things later on I think

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants