where
where節を使って、局所的な定義、つまり適用範囲を限定した定義ができます。
twicesquare x y = mysequare x + mytwice y where twice m = m * 2 mysequare n = n * n
このように、whereを使うことにより、関数の中で関数を定義するような形がとれます。また、whereの後に書かれている関数(これがwhere節)は、同じレベルの関数なのでインデントをそろえてあげる必要があります。
このwhere節は、twicesquareより下げて書かれているので、twicesquareの中でしか使用できません。なので、他の場所から使おうとするとエラーになります。
hasko$ cat twicesquare.hs twicesquare x y = mysequare x + mytwice y where mytwice m = m * 2 mysequare n = n * n myseq x = mysequare x hasko$ hugs Haskell 98 mode: Restart with command line option -98 to enable extensions Type :? for help Prelude> :l twicesquare.hs ERROR "twicesquare.hs":4 - Undefined variable "mysequare" Prelude> :q