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:  dealing with chained functions (Stephen Tetley)
   2. Re:  dealing with chained functions (Alec Benzer)
   3. Re:  dealing with chained functions (Stephen Tetley)
   4. Re:  Real world example of Typeclasses > Interfaces (Brent Yorgey)
   5. Re:  Motivation to Learn Haskell (Rohit Garg)
   6. Re:  Real world example of Typeclasses > Interfaces (Alec Benzer)


----------------------------------------------------------------------

Message: 1
Date: Sat, 4 Sep 2010 08:55:47 +0100
From: Stephen Tetley <stephen.tet...@gmail.com>
Subject: Re: [Haskell-beginners] dealing with chained functions
Cc: beginners@haskell.org
Message-ID:
        <aanlktimwdp7g80f0cz+eifp+honcyuzfr3zdaxab+...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Hello Alec

The first version composes whereas the second one doesn't. With the
first version you should be able to write final like this:

final :: a -> d
final x = f3 $ f2 $ f1 x

or pointfree

final :: a -> d
final = f3 . f2 . f1

With composable functions you may find the intermediate steps f1, f2 &
f3 are useful in other contexts.

Best wishes

Stephen


------------------------------

Message: 2
Date: Sat, 4 Sep 2010 04:06:53 -0400
From: Alec Benzer <alecben...@gmail.com>
Subject: Re: [Haskell-beginners] dealing with chained functions
To: Stephen Tetley <stephen.tet...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <aanlkti=6tcb7wduzkegfczbqxrbrnfq8yj++s6+9q...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

No, ya, I get that differences between the two methods, I was asking
if one of them was generally considered better practice than the
other.


> With composable functions you may find the intermediate steps f1, f2 &
> f3 are useful in other contexts.

Ya, that was what prompted me to think about this in the first place
(needing to use an intermediate value in another context when I had
set up the functions in the latter fashion). Does this fact make
writing the functions like that better practice though, or is it
pretty much left up to context as to which of the two methods to use?

On Sat, Sep 4, 2010 at 3:55 AM, Stephen Tetley <stephen.tet...@gmail.com> wrote:
>
> Hello Alec
>
> The first version composes whereas the second one doesn't. With the
> first version you should be able to write final like this:
>
> final :: a -> d
> final x = f3 $ f2 $ f1 x
>
> or pointfree
>
> final :: a -> d
> final = f3 . f2 . f1
>
> With composable functions you may find the intermediate steps f1, f2 &
> f3 are useful in other contexts.
>
> Best wishes
>
> Stephen
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners


------------------------------

Message: 3
Date: Sat, 4 Sep 2010 09:19:10 +0100
From: Stephen Tetley <stephen.tet...@gmail.com>
Subject: Re: [Haskell-beginners] dealing with chained functions
Cc: beginners@haskell.org
Message-ID:
        <aanlktikyrt6rhrptsc9r57b3+pn+q6fsp+2xt6zqa...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Hi Alec

I think with experience its second nature for people to do the former
- I think by that you could call it best practice.

With the second version you might also find it hard naming the
intermediate steps for real code that does things, this should be an
indication that the first approach is better...


------------------------------

Message: 4
Date: Sat, 4 Sep 2010 12:29:39 -0400
From: Brent Yorgey <byor...@seas.upenn.edu>
Subject: Re: [Haskell-beginners] Real world example of Typeclasses >
        Interfaces
To: beginners@haskell.org
Message-ID: <20100904162939.ga28...@seas.upenn.edu>
Content-Type: text/plain; charset=us-ascii

On Fri, Sep 03, 2010 at 10:51:59PM -0400, Alec Benzer wrote:
> 
> But there's no real way of ensuring an argument implements two interfaces,
> whereas in Haskell you can make sure that an argument belongs to two (or
> however many) typeclasses.
> 
> doSomething :: (Ord a, Eq a, OtherTypeClass a) => a -> Int
> ...
> 
> But as I thought about this, I couldn't seem to think of a practical case
> where this would be useful. 

This is quite useful, and it comes up all the time.  I can't think of
a particular example off the top of my head, but I know I have written
lots of code with multiple type class constraints on the same type.

However, this isn't actually an advantage over Java, since Java
supports multiple interface inheritance.  You can just declare a new
interface that extends several other interfaces, and then use that new
interface instead of having to list multiple ones.

I don't think I'm qualified to comment on the precise differences
between interfaces and type classes, since I haven't thought about it
all that much.  Perhaps others can chime in with some differences.
There is this page on the Haskell wiki:

  http://www.haskell.org/haskellwiki/OOP_vs_type_classes

-Brent


------------------------------

Message: 5
Date: Sat, 4 Sep 2010 21:59:42 +0530
From: Rohit Garg <rpg....@gmail.com>
Subject: Re: [Haskell-beginners] Motivation to Learn Haskell
To: Lorenzo Isella <lorenzo.ise...@gmail.com>
Cc: beginners@haskell.org
Message-ID:
        <aanlktinsvmizt1sqfzypexo-cmqhjjqx43xkm8js=...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

I have explored the possibility of making this switch (numpy/scipy ->
Haskell) occasionally (aka - not VERY thoroughly), but a big hindrance
is Haskell's lack of a matplotlib equivalent.

LAPACK/ODE and cousins are comparatively easier to tackle using the C
FFI. But even there, absence of a SWIG module for Haskell is
inconvenient. SWIG alternatives for haskell might exist, but they
aren't as useful as SWIG for many reasons.

On Sat, Sep 4, 2010 at 4:27 AM, Lorenzo Isella <lorenzo.ise...@gmail.com> wrote:
> 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
>



-- 
Rohit Garg

http://rpg-314.blogspot.com/


------------------------------

Message: 6
Date: Sat, 4 Sep 2010 13:04:43 -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:
        <aanlktinqm-x6jecrbhaxroznrn1lfq9y0hnfxovsm...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

On Sat, Sep 4, 2010 at 12:29 PM, Brent Yorgey <byor...@seas.upenn.edu> wrote:
> On Fri, Sep 03, 2010 at 10:51:59PM -0400, Alec Benzer wrote:
>>
>> But there's no real way of ensuring an argument implements two interfaces,
>> whereas in Haskell you can make sure that an argument belongs to two (or
>> however many) typeclasses.
>>
>> doSomething :: (Ord a, Eq a, OtherTypeClass a) => a -> Int
>> ...
>>
>> But as I thought about this, I couldn't seem to think of a practical case
>> where this would be useful.
>
> This is quite useful, and it comes up all the time.  I can't think of
> a particular example off the top of my head, but I know I have written
> lots of code with multiple type class constraints on the same type.

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).

> However, this isn't actually an advantage over Java, since Java
> supports multiple interface inheritance.  You can just declare a new
> interface that extends several other interfaces, and then use that new
> interface instead of having to list multiple ones.

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? In Java you'd have to declare a whole new interface for
every single different set of interfaces you want your arguments to
conform to, whereas in Haskell you can just specify them in a list. If
cases come up enough where you do need to make sure your arguments
conform to/belong to multiple interfaces/typeclasses, I'd see
Haskell's system as a pretty major improvement, though this is what
prompted me to ask the question in the first place, do such situations
come up enough for this to be as big a benefit as it might seem to be.

> I don't think I'm qualified to comment on the precise differences
> between interfaces and type classes, since I haven't thought about it
> all that much.  Perhaps others can chime in with some differences.
> There is this page on the Haskell wiki:
>
>  http://www.haskell.org/haskellwiki/OOP_vs_type_classes

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?

> -Brent
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>


------------------------------

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 27, Issue 10
*****************************************

Reply via email to