Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/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. Re: Real world example of Typeclasses > Interfaces (Ozgur Akgun) 2. Re: Real world example of Typeclasses > Interfaces (Alec Benzer) 3. Re: Real world example of Typeclasses > Interfaces (Brent Yorgey) 4. Re: Real world example of Typeclasses > Interfaces (Alec Benzer) 5. Re: Re: Motivation to Learn Haskell (A Smith) ---------------------------------------------------------------------- Message: 1 Date: Sat, 4 Sep 2010 18:26:25 +0100 From: Ozgur Akgun <ozgurak...@gmail.com> Subject: Re: [Haskell-beginners] Real world example of Typeclasses > Interfaces To: Alec Benzer <alecben...@gmail.com> Cc: beginners@haskell.org Message-ID: <aanlktimpyscxo1y038tgey0j2x-8+rgz+rko-czhe...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" On 4 September 2010 18:04, Alec Benzer <alecben...@gmail.com> wrote: > What I mean is, if you had a function: something n = > [1..n], and your type was a -> [a], a needs to be declared as (Num a, > Enum a), even though this is sort of redundant, since you can't really > have a number that isn't also enumerable. > Well, you can actually have a Num that isn't Enum. ghci> :info Num class (Eq a, Show a) => Num a where (+) :: a -> a -> a (*) :: a -> a -> a (-) :: a -> a -> a negate :: a -> a abs :: a -> a signum :: a -> a fromInteger :: Integer -> a -- Ozgur Akgun -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20100904/fb52ced4/attachment-0001.html ------------------------------ Message: 2 Date: Sat, 4 Sep 2010 13:41:44 -0400 From: Alec Benzer <alecben...@gmail.com> Subject: Re: [Haskell-beginners] Real world example of Typeclasses > Interfaces To: Ozgur Akgun <ozgurak...@gmail.com> Cc: beginners@haskell.org Message-ID: <aanlktik4f7-=4yob_tn=jxezn-0hriynrcroy4h9p...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 I was speaking more generally, not specifically about the Haskell typeclasses Num and Enum (although actually irrational numbers aren't enumerable now that I think of it, but I also guess that's a relatively moot point since you can't really represent irrational numbers in a programming language) On Sat, Sep 4, 2010 at 1:26 PM, Ozgur Akgun <ozgurak...@gmail.com> wrote: > > On 4 September 2010 18:04, Alec Benzer <alecben...@gmail.com> wrote: >> >> What I mean is, if you had a function: something n = >> [1..n], and your type was a -> [a], a needs to be declared as (Num a, >> Enum a), even though this is sort of redundant, since you can't really >> have a number that isn't also enumerable. > > Well, you can actually have a Num that isn't Enum. > > ghci> :info Num > class (Eq a, Show a) => Num a where > (+) :: a -> a -> a > (*) :: a -> a -> a > (-) :: a -> a -> a > negate :: a -> a > abs :: a -> a > signum :: a -> a > fromInteger :: Integer -> a > > > -- > Ozgur Akgun > ------------------------------ Message: 3 Date: Sat, 4 Sep 2010 13:54:02 -0400 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] Real world example of Typeclasses > Interfaces To: Alec Benzer <alecben...@gmail.com> Cc: beginners@haskell.org Message-ID: <20100904175402.ga10...@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii On Sat, Sep 04, 2010 at 01:04:43PM -0400, Alec Benzer wrote: > On Sat, Sep 4, 2010 at 12:29 PM, Brent Yorgey <byor...@seas.upenn.edu> wrote: > > I know there are cases where this comes up in Haskell, but in certain > cases the needs arises only because of the way Haskell handles > typeclasses. What I mean is, if you had a function: something n = > [1..n], and your type was a -> [a], a needs to be declared as (Num a, > Enum a), even though this is sort of redundant, since you can't really > have a number that isn't also enumerable. I'm talking specifically > about cases where you'd have (TypeClass1 a, TypeClass2 a), and > TypeClass1 doesn't imply TypeClass2 or visa versa (Brandon's example > might have served that purpose, though I'm very new to Haskell and > haven't gotten a full grasp on monads yet). No, I really do mean that this comes up all the time in a nontrivial way. Here's an example I just pulled randomly from a library of mine: -- | Create a scale transformation. scaling :: (HasLinearMap v, HasLinearMap (Scalar v), Scalar (Scalar v) ~ Scalar v, Fractional (Scalar v)) => Scalar v -> Transformation v scaling s = fromLinear $ (s *^) <-> (^/ s) None of those class constraints implies any of the others (not even in theory), and they are all necessary. > Ya but isn't that a pretty big hassle, especially assuming there are > many useful cases where you require a type to belong to multiple > typeclasses? Sure, it's a hassle, but you were looking for examples of why type classes are better than interfaces, and I'm not sure that simple matters of convenience really count. > Read through some of that (will probably read through more later), but > as I did it also occurred to me that I guess the typeclass system > might simply be a necessity to work with the rest of Haskell's type > system? Ie, the point of them isn't their benefits over interfaces, > it's that it's just the way things need to work in order to > effectively connect with algebraic types? No, you don't need type classes to use algebraic data types; see OCaml. Type classes were a major innovation at the time they were added to Haskell, but algebraic data types had been around for a while. -Brent ------------------------------ Message: 4 Date: Sat, 4 Sep 2010 14:42:50 -0400 From: Alec Benzer <alecben...@gmail.com> Subject: Re: [Haskell-beginners] Real world example of Typeclasses > Interfaces To: Brent Yorgey <byor...@seas.upenn.edu> Cc: beginners@haskell.org Message-ID: <aanlktik4pey0z9mbxzclvdz8awxnqsslgbnzcbjpz...@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1 On Sat, Sep 4, 2010 at 1:54 PM, Brent Yorgey <byor...@seas.upenn.edu> wrote: > On Sat, Sep 04, 2010 at 01:04:43PM -0400, Alec Benzer wrote: >> On Sat, Sep 4, 2010 at 12:29 PM, Brent Yorgey <byor...@seas.upenn.edu> wrote: >> >> I know there are cases where this comes up in Haskell, but in certain >> cases the needs arises only because of the way Haskell handles >> typeclasses. What I mean is, if you had a function: something n = >> [1..n], and your type was a -> [a], a needs to be declared as (Num a, >> Enum a), even though this is sort of redundant, since you can't really >> have a number that isn't also enumerable. I'm talking specifically >> about cases where you'd have (TypeClass1 a, TypeClass2 a), and >> TypeClass1 doesn't imply TypeClass2 or visa versa (Brandon's example >> might have served that purpose, though I'm very new to Haskell and >> haven't gotten a full grasp on monads yet). > > No, I really do mean that this comes up all the time in a nontrivial > way. Here's an example I just pulled randomly from a library of mine: > > -- | Create a scale transformation. > scaling :: (HasLinearMap v, HasLinearMap (Scalar v), > Scalar (Scalar v) ~ Scalar v, Fractional (Scalar v)) > => Scalar v -> Transformation v > scaling s = fromLinear $ (s *^) <-> (^/ s) > > None of those class constraints implies any of the others (not even in > theory), and they are all necessary. > >> Ya but isn't that a pretty big hassle, especially assuming there are >> many useful cases where you require a type to belong to multiple >> typeclasses? > > Sure, it's a hassle, but you were looking for examples of why type > classes are better than interfaces, and I'm not sure that simple > matters of convenience really count. For what I meant I'd classify that sort of convenience as a benefit. I mostly was curious about Learn You a Haskell for Great Good's remark that "You can think of [typeclasses] kind of as Java interfaces, only better." Not having to create a new interface every time you want to check for a different collection of typeclasses would qualify as "better" for me. >> Read through some of that (will probably read through more later), but >> as I did it also occurred to me that I guess the typeclass system >> might simply be a necessity to work with the rest of Haskell's type >> system? Ie, the point of them isn't their benefits over interfaces, >> it's that it's just the way things need to work in order to >> effectively connect with algebraic types? > > No, you don't need type classes to use algebraic data types; see > OCaml. Type classes were a major innovation at the time they were > added to Haskell, but algebraic data types had been around for a > while. > > -Brent > ------------------------------ Message: 5 Date: Sat, 4 Sep 2010 22:42:06 +0100 From: A Smith <asmith9...@gmail.com> Subject: Re: [Haskell-beginners] Re: Motivation to Learn Haskell To: "Benjamin L. Russell" <dekudekup...@yahoo.com> Cc: beginners@haskell.org Message-ID: <aanlkti=y989un58hgefm2zd9n=zeaadr4ukdeqmat...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" My tuppence worth is the wonderful conciseness of programs, the way abstraction works, it almost forces you into creating simple very testable functions. These functions will have a well defined uncomplicated transformation, and as such may be re-used to build more complex functions. As a beginner, the templtation is to resist the temptation to implemrnt imperative code, but to link functions together in my thinking like a shell script. With a shell script programs are stated left to right with the output of the leftmost being fed into the next one to the right. I think with Haskell on a similar pattern with a pipeline of functions feed from the right-most one. The next thing is to learn associativity rules and the use of parenthesis, and $ operators. Read everything on www.haskell.org. Confuse yourself by trying to read Prelude source code! -- Andrew Edinburgh,Scotland On 4 September 2010 01:30, Benjamin L. Russell <dekudekup...@yahoo.com>wrote: > Tim Perry <perry2...@yahoo.com> writes: > > > If you do jump in, I'd recommend the Real World Haskell book or the The > Haskell > > School of Expression book. > > Another interesting title is _Programming in Haskell,_ by Graham Hutton > (see > http://www.cs.nott.ac.uk/~gmh/book.html<http://www.cs.nott.ac.uk/%7Egmh/book.html>). > Duncan Coutts has > written a review on the title (see > http://www.cs.nott.ac.uk/~gmh/book-review.pdf<http://www.cs.nott.ac.uk/%7Egmh/book-review.pdf> > ). > > As for motivation for learning Haskell, one motivator is the purely > functional nature of the language, which is referentially transparent > and therefore facilitates reasoning about programs. Haskell has roots > in category theory, and therefore, it is frequently possible to use > category-theoretical reasoning to reason about the correctness of > programs; this cannot be said of most other programming languages. > > -- Benjamin L. Russell > > > > > Good luck, > > Tim > > > > > > > > > > > > ----- Original Message ---- > > From: Lorenzo Isella <lorenzo.ise...@gmail.com> > > To: beginners@haskell.org > > Sent: Fri, September 3, 2010 3:57:26 PM > > Subject: [Haskell-beginners] Motivation to Learn Haskell > > > > Dear All, > > It is my first post to this list and please do not take it as an attempt > to > > start any flamewar. > >>From time to time, I try to find the motivation to learn at least the > > fundamentals of another programming language. > > I normally use R and Python on a daily basis (but I am not that much into > OO > > programming) and have a good knowledge of Fortran and a rather > superficial one > > of C. > > Beside learning a new language as a sort of mind expanding exercise, I > try to > > figure out how and if it can save me some time in my work and how it > measures up > > against other languages. > > These days I tend to rely on R for data analysis and visualization > whereas I use > > Python (in particular Numpy+SciPy) for number crunching (it is very > convenient > > to use scipy/numpy to solve ODE's, manipulate arrays and so on). > > Now, I wonder what benefit I would gain from learning Haskell since I > mainly > > write codes for numerical simulations/data analysis. > > I know Haskell is gaining momentum e.g. in the financial environment (I > happened > > to see Haskell knowledge as a specification in some quant jobs) hence it > must be > > more than suitable for numerical work and, by the little I have > understood so > > far, it allows one to write code really resembling mathematical > expressions (I > > was impressed by guards and curried functions). > > However, it also looks to me (correct me if I am mistaken) that Haskell > is a far > > cry from the wealth of standard and contributed scientific modules you > have in > > Python or R and thanks to which you do not re-implement the wheel > yourself. > > Any thoughts/suggestions are really appreciated. > > Cheers > > > > Lorenzo > > _______________________________________________ > > Beginners mailing list > > Beginners@haskell.org > > http://www.haskell.org/mailman/listinfo/beginners > > > > -- > Benjamin L. Russell / DekuDekuplex at Yahoo dot com > http://dekudekuplex.wordpress.com/ > Translator/Interpreter / Mobile: +011 81 80-3603-6725 > "Furuike ya, kawazu tobikomu mizu no oto." -- Matsuo Basho^ > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20100904/b8c7e984/attachment.html ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 27, Issue 11 *****************************************