# \`where\` syntax in Julia: comparison with Haskell

**URL:** <https://discourse.julialang.org/t/where-syntax-in-julia-comparison-with-haskell/8328>\
**Category:** New to Julia\
**Created:** [January 12, 2018, 9:20pm UTC](https://discourse.julialang.org/t/where-syntax-in-julia-comparison-with-haskell/8328 "2018-01-12T21:20:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SepandMeenu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sepandmeenu/32/8846_2.png) [@SepandMeenu](https://discourse.julialang.org/u/SepandMeenu)\
**Post date:** [January 12, 2018, 9:20pm UTC](https://discourse.julialang.org/t/where-syntax-in-julia-comparison-with-haskell/8328/1 "2018-01-12T21:20:27Z")

</div>

I still cannot correctly grasp the `where` syntax in Julia.  
I’d like to know if one can use Julia’s `where` keyword as in Haskell; e.g., similar to the following Haskell snippet:

```julia
len x y = sqrt (sq x + sq y)
  where
    sq a = a * a

```

the Julia code for which could be

```julia
len(x, y) = sqrt( sq(x) + sq(y) ) where
   sq(a) = a * a
end

```

Please let me know if this is (or will be) possible.

---

<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:** [January 12, 2018, 9:43pm UTC](https://discourse.julialang.org/t/where-syntax-in-julia-comparison-with-haskell/8328/2 "2018-01-12T21:43:17Z")

</div>

No there’s no similarity at all.

```julia
len(x, y) = let sq(a) = a * a
    sqrt(sq(x) + sq(y))
end

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 13, 2018, 7:48am UTC](https://discourse.julialang.org/t/where-syntax-in-julia-comparison-with-haskell/8328/3 "2018-01-13T07:48:05Z")

</div>

They are completely different things. In Haskell, `where` resolves bindings later, similarly to `let` (if I remember correctly; haven’t used Haskell for a while).

In Julia, `where` is used for the construction of [UnionAll types](https://docs.julialang.org/en/latest/manual/types/#UnionAll-Types-1) and [parametric methods](https://docs.julialang.org/en/latest/manual/methods/#Parametric-Methods-1). The manual has many examples, perhaps they might help.
