Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: filterM function (Shishir Srivastava)
----------------------------------------------------------------------
Message: 1
Date: Wed, 22 Apr 2015 10:22:11 +0100
From: Shishir Srivastava <[email protected]>
To: beginners <[email protected]>, Mike Meyer <[email protected]>
Subject: Re: [Haskell-beginners] filterM function
Message-ID:
<CALe5RTtZSRyeriC2M=wxtmyprek+bfyaeu6dpsibabncr5p...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi Mike,
Thanks for your response. I was aware that 'casting' doesn't really fit in
Haskell vocab but for the lack of better word used it.
My question was however more towards the usage of [Bool] in the 'if'
statement of the filterM function.
More precisely - How does 'if [True, False] then x else y' work , because
when I do this in GHCi it throws up the following error ?
*>>Couldn't match expected type `Bool' with actual type `[Bool]'*
Clearly the 'if' construct does not take a list of Boolean but a single
Boolean value so how does filterM use it in it's implementation.
Hope have made myself clear this time.
Thanks,
Shishir
> From: Mike Meyer <[email protected]>
> To: The Haskell-Beginners Mailing List - Discussion of primarily
> beginner-level topics related to Haskell <[email protected]>
> Cc:
> Date: Wed, 22 Apr 2015 04:15:31 -0500
> Subject: Re: [Haskell-beginners] filterM function
> On Wed, Apr 22, 2015 at 3:31 AM, Shishir Srivastava <
> [email protected]> wrote:
>
>> I still don't quite understand how 'flg' being a boolean [] is used in
>> the last 'if statement' of implementation because when I try to do the
>> same thing outside in GHCi it fails miserably even though I am casting it
>> to [Int] -
>>
>> --
>> return (if [True, False] then "4" else "3")::[Int]
>>
>
> "cast" is a misnomer in Haskell. When you add a type to an expression, you
> aren't changing the type of the expression like a C-style cast, but picking
> out a type from the set of possible types for that expression.
>
> Ignoring the if part and and focusing on return, which has a type Monad m
> => a -> m a. [Int] is equivalent to [] Int, so [] would be the Monad, and a
> is Int. While 3 can be an Int, "3", can't. So you could do return 3 ::
> [Int] or equivalently return 3 :: [] Int to get [3], you can't do return
> "3" :: [Int], because "3" can't be an Int. You can do return "3" ::
> [String], since "3" is a string. Just to show the range of possibilities,
> you can do return 3 :: IO Float, and get back 3.0 as an IO action. The
> monad in the type is IO, and 3 can be interpreted as a Float.
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150422/b4c8d983/attachment-0001.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 82, Issue 28
*****************************************