[Haskell-beginners] About scope range: outside of the do-block

Gesh gesh at gesh.uni.cx
Sun Apr 20 14:06:30 UTC 2014


On April 20, 2014 4:38:05 PM GMT+03:00, "S. H. Aegis" <shaegis at gmail.com> wrote:
>Oh, I'm sorry.
>I delete some of commented lines.
>Sorry for confusing.
>
>Error occurred in
>sortedNamesList = sort $ nameList names
>
>Thank you.
>
>
>2014-04-20 22:17 GMT+09:00 Norbert Melzer <timmelzer at gmail.com>:
>
>>
>> Am 20.04.2014 14:58 schrieb "S. H. Aegis" <shaegis at gmail.com>:
>>
>> > namesScores.hs:31:35: Not in scope: `names'
>> > Failed, modules loaded: none.
>>
>> The code you posted has only 21 lines while your error message
>denotes an
>> error in line 31, so there is something missing.
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>

In general, variables defined locally in one scope are not floated to external scopes.
Thus, your question is analogous to asking:
Given the following code:
foo = ...
  where bar = ...
baz = ...
Can I call bar from baz? The answer being no, you can't, unless you pass bar as a parameter to baz (or use a Reader monad, which is equivalent).

Hoping to help,
Gesh


More information about the Beginners mailing list