Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Array{Any} when collecting chained generators #90

Open
CarloLucibello opened this issue Oct 30, 2016 · 7 comments
Open

Array{Any} when collecting chained generators #90

CarloLucibello opened this issue Oct 30, 2016 · 7 comments

Comments

@CarloLucibello
Copy link
Contributor

Collecting a generator works as expected

julia> collect(i for i=1:10)
10-element Array{Int64,1}:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10

But if you chain it

julia> collect(chain(i for i=1:10))
10-element Array{Any,1}:
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10

What puzzles me is that eltype(i for i=1:10) == Any

@iamed2
Copy link
Collaborator

iamed2 commented Oct 30, 2016

eltype(i for i=1:10) == Any is an issue, I think. But probably an issue for JuliaLang/julia. I figure there could be two solutions:

  1. Something involving Base.return_types to do inference on the generator function in the general case

OR

  1. Special case a generator which just returns the results of an iterator (I think this would need some parser attention, i.e., have the parser use identity instead of (x)->x so that we can dispatch on it after.

@yuyichao
Copy link
Contributor

eltype(i for i=1:10) == Any is an issue,

It's not an issue.

  1. Something involving Base.return_types to do inference on the generator function in the general case

And we shouldn't do this.

I think we just shouldn't rely on eltype in collect.

@iamed2
Copy link
Collaborator

iamed2 commented Oct 30, 2016

I wasn't sure whether Base.return_types was fair game or not.

I was thinking up some @generated solution until I realized that I can tell collect to not rely on eltype fairly simply. This line solves things:

Base.iteratoreltype(c::Chain) = EltypeUnknown()

but we may not need it with #85 (reviewing performance for that now). We will.

@CarloLucibello
Copy link
Contributor Author

fixed by #85

@iamed2
Copy link
Collaborator

iamed2 commented Jan 21, 2017

No, it wasn't

@iamed2 iamed2 reopened this Jan 21, 2017
iamed2 added a commit that referenced this issue Jan 21, 2017
@CarloLucibello
Copy link
Contributor Author

ouch, sorry, did the wrong test, ranges instead of iterators

@iamed2
Copy link
Collaborator

iamed2 commented Jan 21, 2017

That's okay :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants