# The ‘where’ keyword

**URL:** <https://discourse.julialang.org/t/the-where-keyword/107030>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [December 2, 2023, 2:27am UTC](https://discourse.julialang.org/t/the-where-keyword/107030 "2023-12-02T02:27:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiang\_ming\_zhang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jiang_ming_zhang/32/204063_2.png) [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)\
**Post date:** [December 2, 2023, 2:27am UTC](https://discourse.julialang.org/t/the-where-keyword/107030/1 "2023-12-02T02:27:21Z")

</div>

> function dimension(::BoseFS{N,M}) where {N,M}  
> return binomial(BigInt(N + M - 1), BigInt(N))  
> end

what does the ‘where’ keyword mean? I tend to interprete it like the english clause, but I cannot make sense of it

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [December 2, 2023, 3:13am UTC](https://discourse.julialang.org/t/the-where-keyword/107030/2 "2023-12-02T03:13:36Z")

</div>

Agreed. The Julia `where` keyword seems only about 2/3 aligned with the English word “where” and how it sets up subordinate clauses, and I haven’t yet found documentation that provides an alternate way to understand it.

EDIT: Of course, after saying that I look at the docs and find the answer immediately:

```julia

help?> where
search: where

  where

  The where keyword creates a type that is an iterated union of other types, over all values of some variable. For example Vector{T} where
  T<:Real includes all Vectors where the element type is some kind of Real number.

  The variable bound defaults to Any if it is omitted:

  Vector{T} where T # short for `where T<:Any`

  Variables can also have lower bounds:

  Vector{T} where T>:Int
  Vector{T} where Int<:T<:Real

```

the key part being "where T # short for `where T<:Any`

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [December 2, 2023, 3:15am UTC](https://discourse.julialang.org/t/the-where-keyword/107030/3 "2023-12-02T03:15:53Z")

</div>

Remember you can use the `?` in the repl to bring up help for any keyword.

```julia

help?> where
search: where

  where

  The where keyword creates a type that is an iterated union of other types, over all values of some variable. For example
  Vector{T} where T<:Real includes all Vectors where the element type is some kind of Real number.

  The variable bound defaults to Any if it is omitted:

  Vector{T} where T # short for `where T<:Any`

  Variables can also have lower bounds:

  Vector{T} where T>:Int
  Vector{T} where Int<:T<:Real

  There is also a concise syntax for nested where expressions. For example, this:

  Pair{T, S} where S<:Array{T} where T<:Number

  can be shortened to:

  Pair{T, S} where {T<:Number, S<:Array{T}}

  This form is often found on method signatures.

  Note that in this form, the variables are listed outermost-first. This matches the order in which variables are substituted
  when a type is "applied" to parameter values using the syntax T{p1, p2, ...}.

```

> [@John\_Gibson](#):
>
> The Julia `where` keyword seems only about 2/3 aligned with the English word “where” and how it sets up subordinate clauses

it’s `T where T<:Foo`, but you can leave out the `<:Foo` if `Foo` is `Any`.

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [December 2, 2023, 3:18am UTC](https://discourse.julialang.org/t/the-where-keyword/107030/4 "2023-12-02T03:18:18Z")

</div>

Yep. 🙂
