<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Apr 22, 2015 at 3:31 AM, Shishir Srivastava <span dir="ltr"><<a href="mailto:shishir.srivastava@gmail.com" target="_blank">shishir.srivastava@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I still don't quite understand how '<font face="monospace, monospace">flg</font>' being a boolean [] is used in the last <font face="monospace, monospace">'if</font> 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] - </div><div><br></div><div>--</div><div><font face="monospace, monospace">return (if [True, False] then "4" else "3")::[Int]</font></div></div></blockquote><div><br></div><div>"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.</div><div><br></div><div>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.</div></div></div></div>