# Enum type vs. enum like parameter name

**URL:** https://discourse.julialang.org/t/enum-type-vs-enum-like-parameter-name/54790
**Category:** New to Julia
**Tags:** enum
**Created:** [February 7, 2021, 1:23pm UTC](https://discourse.julialang.org/t/enum-type-vs-enum-like-parameter-name/54790 "2021-02-07T13:23:18Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![xor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xor/32/21782_2.png) [@xor](https://discourse.julialang.org/u/xor)
#### Post date: [February 7, 2021, 1:23pm UTC](https://discourse.julialang.org/t/enum-type-vs-enum-like-parameter-name/54790/1 "2021-02-07T13:23:18Z")

</div>

I have the following behavior (contrived example for demo purposes)

```julia
@enum Fruit apple orange kiwi
f(apple::String, fruit::Array{Fruit}) = fruit[1] == apple::Fruit
f("not apple", [apple])

ERROR: TypeError: in typeassert, expected Fruit, got a value of type String

```

On the other hand this works as expected

```julia
f(param1::String, fruit::Array{Fruit}) = fruit[1] == apple::Fruit
f("not apple", [apple])

true

```

It looks like the name of a parmeter (apple) clashes with the name of an enum (apple) and wins. Is there a way to specify within the function body that “apple” refers to the enum type?

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [February 7, 2021, 2:03pm UTC](https://discourse.julialang.org/t/enum-type-vs-enum-like-parameter-name/54790/2 "2021-02-07T14:03:39Z")

</div>

In the REPL case it could be:

```julia
f(apple::String, fruit::Array{Fruit}) = fruit[1] == Main.apple

```

---

<div class="post-metadata">

### Author: ![xor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xor/32/21782_2.png) [@xor](https://discourse.julialang.org/u/xor)
#### Post date: [February 7, 2021, 2:10pm UTC](https://discourse.julialang.org/t/enum-type-vs-enum-like-parameter-name/54790/3 "2021-02-07T14:10:11Z")

</div>

You are right - how would a non REPL solution look like?

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [February 7, 2021, 2:12pm UTC](https://discourse.julialang.org/t/enum-type-vs-enum-like-parameter-name/54790/4 "2021-02-07T14:12:20Z")

</div>

Depends on your setup. If the enum is defined in a module `X`, just use `X.apple`.

---

<div class="post-metadata">

### Author: ![xor](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xor/32/21782_2.png) [@xor](https://discourse.julialang.org/u/xor)
#### Post date: [February 7, 2021, 2:40pm UTC](https://discourse.julialang.org/t/enum-type-vs-enum-like-parameter-name/54790/5 "2021-02-07T14:40:34Z")

</div>

Right so if the enum is defined in module `X` then it is `X.enumname` otherwise (REPL or not) it is `Main.enumname`

Also, turns out that expression `apple::Fruit` is a type assertion - a runtime check on the actual type, not a type specification.

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [February 7, 2021, 2:42pm UTC](https://discourse.julialang.org/t/enum-type-vs-enum-like-parameter-name/54790/6 "2021-02-07T14:42:50Z")

</div>

Yes, but there may be more possibilities I can’t imagine right now.
