# Why this constructor is extremly slow? Infinity Loop in Varargs function

**URL:** <https://discourse.julialang.org/t/why-this-constructor-is-extremly-slow-infinity-loop-in-varargs-function/9101>\
**Category:** Performance\
**Created:** [February 16, 2018, 4:46am UTC](https://discourse.julialang.org/t/why-this-constructor-is-extremly-slow-infinity-loop-in-varargs-function/9101 "2018-02-16T04:46:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)\
**Post date:** [February 16, 2018, 4:46am UTC](https://discourse.julialang.org/t/why-this-constructor-is-extremly-slow-infinity-loop-in-varargs-function/9101/1 "2018-02-16T04:46:48Z")

</div>

This constructor receives a wrong type actually but I do not receive any error, it seems that the compiler is in some infinite loop… I cannot figure out why? I guess I made some mistake, cause this happens on both v0.6 and v0.7

My Julia version is

```julia
julia> versioninfo()
Julia Version 0.6.0
Commit 9036443 (2017-06-19 13:05 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-4200M CPU @ 2.50GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)

```

```julia
const Ket{N} = NTuple{N, Int}

ket(spins::Int...) = Ket(spins)

struct LHamiltonian{T, N}
    # kets::Vecotr{Ket{N}}
    # vals::Vector{T}
    data::Vector{Tuple{T, Ket{N}}}
end

LHamiltonian(args...) = LHamiltonian([each for each in args])

LH = LHamiltonian(
    [(1, ket(0, 0)), (1, ket(1, 0))],
    [(-1, ket(1, 1))],
    [(1, ket(0, 0)), (-1, ket(0, 1)), (1, ket(1, 0))],
    [(-1, ket(1, 1))]
)

```

This also happens on this version, I built this from master a few days ago.

```julia
julia> versioninfo()
Julia Version 0.7.0-DEV.3967
Commit 755f6a5 (2018-02-14 05:00 UTC)
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i5-4200M CPU @ 2.50GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)
Environment:
  JULIA_PKGDIR = /home/roger/julia/pkgs

```

---

<div class="post-metadata">

**Author:** ![Gnimuc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gnimuc/32/2194_2.png) [@Gnimuc](https://discourse.julialang.org/u/Gnimuc)\
**Post date:** [February 16, 2018, 5:30am UTC](https://discourse.julialang.org/t/why-this-constructor-is-extremly-slow-infinity-loop-in-varargs-function/9101/2 "2018-02-16T05:30:48Z")

</div>

An MWE is:

```julia
julia> foo(args...) = foo([each for each in args])
foo (generic function with 1 method)

julia> foo([1,2])

```

it will recursively create and collect generators.

---

<div class="post-metadata">

**Author:** ![Roger-luo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roger-luo/32/3399_2.png) [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)\
**Post date:** [February 16, 2018, 5:32am UTC](https://discourse.julialang.org/t/why-this-constructor-is-extremly-slow-infinity-loop-in-varargs-function/9101/3 "2018-02-16T05:32:40Z")

</div>

I see… Thanks!
