Skip to content

Unintuitive Functor and Applicative instances #54

@rihardsk

Description

@rihardsk

I had expected that S.map and fmap would work the same. E.g., to my mind these should have been equivalent:

x = S.map (+1) $ S.each [1..10]
x' = fmap (+1) $ S.each [1..10] -- this gives a compiler error

Because that's what happens to lists with map and fmap. Instead fmap only affects the result of the stream.

Similarly, with the Applicative instance:

y = S.zipWith (/) (S.each [1..10]) (S.each [2..11])
y' = (/) <$> S.each [1..10] <*> S.each [2..11] -- this gives a compiler error

What is the motivation behind such an implementation? There's certainly a downside for me here since, it seems, I can't have a general function working on Functors that would do the same thing for lists and streams.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions