Send Beginners mailing list submissions to beginners@haskell.org 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 beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Polymorphism ad hoc (OxFord) 2. Re: Polymorphism ad hoc (Arjun Comar) 3. Case vs Guards. I still don't know what is the difference (Semih Masat) 4. Re: Case vs Guards. I still don't know what is the difference (Semih Masat) 5. Re: Case vs Guards. I still don't know what is the difference (Theodore Lief Gannon) ---------------------------------------------------------------------- Message: 1 Date: Wed, 6 Jul 2016 18:04:57 +0200 From: OxFord <fordfo...@gmail.com> To: "beginners@haskell.org" <beginners@haskell.org> Subject: [Haskell-beginners] Polymorphism ad hoc Message-ID: <CAPQ-+H+BqtKVWmNv78GGfUMq=zAk+85TA3w6h9ci=qm8ty8...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Hello, why does haskell support only parametric polymorphism? Is it because ad hoc p. || multiple dispatch is bad in general? King Regards, Ford -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160706/36f34d9e/attachment-0001.html> ------------------------------ Message: 2 Date: Wed, 06 Jul 2016 16:19:37 +0000 From: Arjun Comar <nru...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Polymorphism ad hoc Message-ID: <cadjrcrwr5kso1snjt_mobjtlyp5jo9axx72-llpydjy61ot...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Hi Ford, Haskell does support ad-hoc polymorphism via type classes. In short, class Foo a where -- type declarations for related sets of functions that are polymorphic in a go here instance Foo Int where -- function definitions with a specialized to Int go here. The Show class is probably a fairly simple example you can play with in ghci. data Test = Test instance Show Test where -- show :: Test -> String show t = "Hello World" Thanks, Arjun On Wed, Jul 6, 2016 at 12:05 PM OxFord <fordfo...@gmail.com> wrote: > Hello, > > why does haskell support only parametric polymorphism? > > Is it because ad hoc p. || multiple dispatch is bad in general? > > > King Regards, > > Ford > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160706/1e82699a/attachment-0001.html> ------------------------------ Message: 3 Date: Thu, 7 Jul 2016 03:43:42 +0300 From: Semih Masat <masat.se...@gmail.com> To: beginners@haskell.org Subject: [Haskell-beginners] Case vs Guards. I still don't know what is the difference Message-ID: <cap7z+mlantj-0hc2tz1vqmuzzvemet2jxmarcqtdewrbtar...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Hello, I am new to Haskell and trying to learn it with learnyouahaskell.com and Pluralsight Haskell course. And i have a very noob question. I understand that *if .. else* is just a syntactic sugar over *case. *But what about guards then ? Are guards also *case *in different syntax ? Or vice versa ? Like with an example. anyEven nums | (length (removeOdd nums)) > 0 = True | otherwise = False anyEven' nums = case (removeOdd nums) of [] -> False (x:xs) -> True I can do the same thing with both of them. As i understand the only different thing is, with *case *i can manipulate the parameter (like here in the example i used removeOdd) and can use the manipulated parameter to decide what to do after that. So i will not need to use removeOdd function inside the case. ( maybe i will need to use in every guard definition if i choose to use guards ) Is this it? Is this the only difference between them ? And if it is, why haskell needed do implement both of them. Can't we use function like removeOdd before using it on case or guard functions ? Thanks, and sorry if my english is bad. Semih Masat -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160707/2bacca53/attachment-0001.html> ------------------------------ Message: 4 Date: Thu, 7 Jul 2016 04:16:56 +0300 From: Semih Masat <masat.se...@gmail.com> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Case vs Guards. I still don't know what is the difference Message-ID: <cap7z+mj7ycp974ld51ppl9n-umgjja0zsyovybwrrvpuj1m...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" Sorry, if i am flooding. To make it clear what i wanted to say in last section on previous mail. Lets say i have a list of numbers and i want to do different things in case of different even numbers on that list. If i use guards i will do it like this : nums = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17] howManyEvens = length(removeOdd(nums)) isItOk count | count > 10 = "Too much" | count > 8 = "Isn't this a little much?" | count > 5 = "I think this is ok" | count > 3 = "Little more please" | count > 0 = "Ooo, cmon" | otherwise = "We gonna die" result = isItOk howManyEvens This is a very stupid example but this will work i guess. And if i wanted to this with *case* , i will do it like; isItOk' nums = case (length(removeOdd(nums))) of 10 -> "Too much" 8 -> "Isn't this a little much?" 5 -> "I think this is ok" 3 -> "Little more please" 0 -> "Ooo, cmon" x -> "i don't even" So the only different thing is i didn't need to create *howManyEvens* constant. PS: While i writing this. I realized that with case, i need to use pattern matching but with guards i can use other functions if i wanted to. ( like count > 10 ) Sorry for asking prematurely. And if anyone reaches this email by google search. Look at this explanation : http://stackoverflow.com/a/4156831 To the authors : Please, if you writing a book a blog post about haskell. Don't create same function in different styles. We don't understand which one we need to use and why we have all different choices. Thanks. Semih On Thu, Jul 7, 2016 at 3:43 AM, Semih Masat <masat.se...@gmail.com> wrote: > Hello, > > I am new to Haskell and trying to learn it with learnyouahaskell.com and > Pluralsight Haskell course. > > And i have a very noob question. > > I understand that *if .. else* is just a syntactic sugar over *case. *But > what about guards then ? > > Are guards also *case *in different syntax ? Or vice versa ? Like with an > example. > > > anyEven nums > | (length (removeOdd nums)) > 0 = True > | otherwise = False > > > anyEven' nums = case (removeOdd nums) of > [] -> False > (x:xs) -> True > > I can do the same thing with both of them. > > As i understand the only different thing is, with *case *i can manipulate > the parameter (like here in the example i used removeOdd) and can use the > manipulated parameter to decide what to do after that. > So i will not need to use removeOdd function inside the case. ( maybe i > will need to use in every guard definition if i choose to use guards ) > > Is this it? > > Is this the only difference between them ? > > And if it is, why haskell needed do implement both of them. Can't we use > function like removeOdd before using it on case or guard functions ? > > > Thanks, and sorry if my english is bad. > > Semih Masat > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160707/c3b04427/attachment-0001.html> ------------------------------ Message: 5 Date: Wed, 6 Jul 2016 18:43:35 -0700 From: Theodore Lief Gannon <tan...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Case vs Guards. I still don't know what is the difference Message-ID: <cajopsubj9g__di9azm-rnpnhtrf0ti53v4zpmvt-weq9c67...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" One important feature of guards is that passing a pattern but failing all the guards falls through to the next pattern. Toy example: maybeGT5 x | x > 5 = Just x maybeGT5 _ = Nothing On Jul 6, 2016 6:17 PM, "Semih Masat" <masat.se...@gmail.com> wrote: > Sorry, if i am flooding. > > To make it clear what i wanted to say in last section on previous mail. > > > > Lets say i have a list of numbers and i want to do different things in > case of different even numbers on that list. > > If i use guards i will do it like this : > > nums = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17] > howManyEvens = length(removeOdd(nums)) > > isItOk count > | count > 10 = "Too much" > | count > 8 = "Isn't this a little much?" > | count > 5 = "I think this is ok" > | count > 3 = "Little more please" > | count > 0 = "Ooo, cmon" > | otherwise = "We gonna die" > > result = isItOk howManyEvens > > This is a very stupid example but this will work i guess. > > And if i wanted to this with *case* , i will do it like; > > isItOk' nums = case (length(removeOdd(nums))) of > 10 -> "Too much" > 8 -> "Isn't this a little much?" > 5 -> "I think this is ok" > 3 -> "Little more please" > 0 -> "Ooo, cmon" > x -> "i don't even" > > So the only different thing is i didn't need to create *howManyEvens* > constant. > > > PS: While i writing this. I realized that with case, i need to use pattern > matching but with guards i can use other functions if i wanted to. ( like > count > 10 ) > Sorry for asking prematurely. And if anyone reaches this email by google > search. Look at this explanation : http://stackoverflow.com/a/4156831 > > To the authors : Please, if you writing a book a blog post about haskell. > Don't create same function in different styles. We don't understand which > one we need to use and why we have all different choices. > > Thanks. > Semih > > On Thu, Jul 7, 2016 at 3:43 AM, Semih Masat <masat.se...@gmail.com> wrote: > >> Hello, >> >> I am new to Haskell and trying to learn it with learnyouahaskell.com and >> Pluralsight Haskell course. >> >> And i have a very noob question. >> >> I understand that *if .. else* is just a syntactic sugar over *case. *But >> what about guards then ? >> >> Are guards also *case *in different syntax ? Or vice versa ? Like with >> an example. >> >> >> anyEven nums >> | (length (removeOdd nums)) > 0 = True >> | otherwise = False >> >> >> anyEven' nums = case (removeOdd nums) of >> [] -> False >> (x:xs) -> True >> >> I can do the same thing with both of them. >> >> As i understand the only different thing is, with *case *i can >> manipulate the parameter (like here in the example i used removeOdd) and >> can use the manipulated parameter to decide what to do after that. >> So i will not need to use removeOdd function inside the case. ( maybe i >> will need to use in every guard definition if i choose to use guards ) >> >> Is this it? >> >> Is this the only difference between them ? >> >> And if it is, why haskell needed do implement both of them. Can't we use >> function like removeOdd before using it on case or guard functions ? >> >> >> Thanks, and sorry if my english is bad. >> >> Semih Masat >> > > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160706/219ee254/attachment.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 97, Issue 4 ****************************************