# Inconsistent use of type parameters?

**URL:** https://discourse.julialang.org/t/inconsistent-use-of-type-parameters/3544
**Category:** New to Julia
**Created:** [May 5, 2017, 5:45pm UTC](https://discourse.julialang.org/t/inconsistent-use-of-type-parameters/3544 "2017-05-05T17:45:53Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ndbecker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ndbecker/32/10829_2.png) [@ndbecker](https://discourse.julialang.org/u/ndbecker)
#### Post date: [May 5, 2017, 5:45pm UTC](https://discourse.julialang.org/t/inconsistent-use-of-type-parameters/3544/1 "2017-05-05T17:45:53Z")

</div>

struct A{T}  
nothing  
end

Can we use the name A without a parameter?  
julia\> A  
A

Yes, how about with a type parameter?  
julia\> A{Int64}  
A{Int64}  
no problem. But:

function b{T}(x::T)  
return x  
end  
b (generic function with 1 method)

Name ‘b’ without parameter?  
julia\> b  
b (generic function with 1 method)  
yes, but  
julia\> b{Int64}  
ERROR: TypeError: Type{…} expression: expected UnionAll, got #b  
Stacktrace:  
[1] macro expansion at ./REPL.jl:97 [inlined]  
[2] (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:73

Naming the function with a type parameter gives a (strange!) error  
Seems inconsistent to this naive user, and the message seems mysterious.

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [May 5, 2017, 5:48pm UTC](https://discourse.julialang.org/t/inconsistent-use-of-type-parameters/3544/2 "2017-05-05T17:48:40Z")

</div>

I agree that this can be confusing. Fortunately, Julia v0.6 introduces a new syntax for `b`:

```julia
function b(x::T) where T
  return x
end

```

which no longer (incorrectly) implies that you could write `b{Int}`.

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [May 5, 2017, 5:55pm UTC](https://discourse.julialang.org/t/inconsistent-use-of-type-parameters/3544/3 "2017-05-05T17:55:21Z")

</div>

To expand on this a little, in Julia there are two types of constructors

- **Inner:** these accept type parameters (i.e. the arguments in the `{}`) and are declared inside the `type` declaration. i.e. they are called like `XType{T}(args...)`
- **Outer:** these do not take any type parameters and are declared outside of the `type` declaration. i.e. they are called like `XType(args...)`.

This seems quite confusing at first, but is actually quite useful as it is helpful to be able to declare either type of constructor. However, like @rdeits pointed out, there is now an additional syntax available for sorting this out.

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [May 5, 2017, 6:01pm UTC](https://discourse.julialang.org/t/inconsistent-use-of-type-parameters/3544/4 "2017-05-05T18:01:09Z")

</div>

The only “inconsistency” is that we don’t allow explicitly specifing the type parameters for a method. And that’s also related to that type cannot be overload but functions can.
