`where` syntax in Julia: comparison with Haskell

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:

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

the Julia code for which could be

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.

No there’s no similarity at all.

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

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 and parametric methods. The manual has many examples, perhaps they might help.

1 Like