Send Beginners mailing list submissions to
[email protected]
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
[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: Type classes and synonyms (John Dorsey)
2. Re: Type classes and synonyms (John Dorsey)
3. Re: Type classes and synonyms (Chadda? Fouch?)
4. Re: Type classes and synonyms (Daniel Fischer)
5. Re: Type classes and synonyms (John Dorsey)
6. Re: Type classes and synonyms (Philip Scott)
7. Re: Type classes and synonyms (Isaac Dupree)
8. Re: Type classes and synonyms (Felipe Lessa)
9. Re: Type classes and synonyms (Tony Morris)
10. Re: Re: Is Haskell for me? (Ben Lippmeier)
----------------------------------------------------------------------
Message: 1
Date: Sat, 21 Nov 2009 16:13:49 -0500
From: John Dorsey <[email protected]>
Subject: Re: [Haskell-beginners] Type classes and synonyms
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-1
Chaddaï Fouché wrote:
> second :: (b -> c) -> (d, b) -> (d, c)
> which corresponds exactly to the action of second you described
> (that's the only function that could have this type, except bottom of
> course).
Nonsense! There are several perfectly good Haskell functions with that
type. I count seven:
second :: (b -> c) -> (d, b) -> (d, c)
second = Control.Arrow.second
second = undefined
second = const undefined
second = const (const undefined)
second = const (const (undefined,undefined))
second f (d,b) = (undefined, f b)
second f (d,b) = (d, undefined)
Why I'm stickling on that point on the beginners list, however, is a
mystery. I'll go write a more useful response, in contrition.
John
------------------------------
Message: 2
Date: Sat, 21 Nov 2009 16:23:26 -0500
From: John Dorsey <[email protected]>
Subject: Re: [Haskell-beginners] Type classes and synonyms
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Philip,
> I merge my lists into a list of pairs before I do anything with them so
> unevenness isn't a problem; I was just trying t convince haskell that I could
> use nice operators like '+' on my derived type.
There's another way to use nice operators like '+', in cases where the type
you're using it with just doesn't make sense as an instance of Class Num.
(I think there's an argument that your [(date,value)] type isn't a number
and shouldn't be a Num, but I'm not going to go there.)
Every module can have its own definition for each name, such as the operator
(+). So in your module (eg. module Main, or module DateValueSeries), you
can go ahead and define your own (+). The major caveat is making sure you
don't conflict with the default (+), which lives in module Prelude, which is
normally automatically brought into scope.
So you could do this:
-- file DateValueSeries.hs
module DateValueSeries where
import Prelude hiding ((+))
(+) :: [(Int,Int)] -> [(Int,Int)] -> [(Int,Int)]
(+) = addSkip
addSkip = ...
-- file main.hs
import Prelude hiding ((+))
import DateValueSeries
dvlist1 = [(0,100)]
dvlist2 = ...
dvlist3 = dvlist1 + dvlist2
The code is incomplete and untested, of course.
The basic idea is that you can use (+) for something that isn't exactly
addition (although you're choosing that name because it's clearly related to
addition). Unlike the examples using Class Num your (+) has nothing to do
with the normal (+); it just has the same name.
John
------------------------------
Message: 3
Date: Sat, 21 Nov 2009 22:23:38 +0100
From: Chadda? Fouch? <[email protected]>
Subject: Re: [Haskell-beginners] Type classes and synonyms
To: John Dorsey <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Sat, Nov 21, 2009 at 10:13 PM, John Dorsey <[email protected]> wrote:
> Chaddaï Fouché wrote:
>
>> second :: (b -> c) -> (d, b) -> (d, c)
>> which corresponds exactly to the action of second you described
>> (that's the only function that could have this type, except bottom of
>> course).
>
> Nonsense! Â There are several perfectly good Haskell functions with that
> type. Â I count seven:
>
> second :: (b -> c) -> (d, b) -> (d, c)
> second = Control.Arrow.second
> second = undefined
> second = const undefined
> second = const (const undefined)
> second = const (const (undefined,undefined))
> second f (d,b) = (undefined, f b)
> second f (d,b) = (d, undefined)
Right... Let's just say functions that may be evaluated to normal form
if their parameters can be evaluated to normal form.
Nitpicker !! :P
--
Jedaï
------------------------------
Message: 4
Date: Sat, 21 Nov 2009 22:27:20 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Type classes and synonyms
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Samstag 21 November 2009 22:13:49 schrieb John Dorsey:
> Chaddaï Fouché wrote:
> > second :: (b -> c) -> (d, b) -> (d, c)
> > which corresponds exactly to the action of second you described
> > (that's the only function that could have this type, except bottom of
> > course).
>
> Nonsense! There are several perfectly good Haskell functions with that
> type. I count seven:
>
> second :: (b -> c) -> (d, b) -> (d, c)
> second = Control.Arrow.second
> second = undefined
> second = const undefined
> second = const (const undefined)
> second = const (const (undefined,undefined))
> second f (d,b) = (undefined, f b)
> second f (d,b) = (d, undefined)
I don't see
second f (d,b) = (undefined, f undefined)
second f (d,b) = (d, f undefined)
in there.
>
> Why I'm stickling on that point on the beginners list, however, is a
> mystery. I'll go write a more useful response, in contrition.
>
> John
------------------------------
Message: 5
Date: Sat, 21 Nov 2009 16:44:50 -0500
From: John Dorsey <[email protected]>
Subject: Re: [Haskell-beginners] Type classes and synonyms
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Daniel Fischer re-nitpicked:
>
> I don't see
>
> second f (d,b) = (undefined, f undefined)
> second f (d,b) = (d, f undefined)
>
> in there.
Brilliant! I thought I might have missed something, hence "I count seven"
instead of "there are seven".
John
------------------------------
Message: 6
Date: Sat, 21 Nov 2009 22:25:35 +0000
From: Philip Scott <[email protected]>
Subject: Re: [Haskell-beginners] Type classes and synonyms
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="iso-8859-1"
Thanks John,
> Every module can have its own definition for each name, such as the
> operator (+). So in your module (eg. module Main, or module
> DateValueSeries), you can go ahead and define your own (+). The major
> caveat is making sure you don't conflict with the default (+), which lives
> in module Prelude, which is normally automatically brought into scope.
That actually quite nicely solves the problem... it feels almost a little too
easy, after spending the evening getting my mind wrapped up with Arrows :)
Thank you very much for your help.
- Philip
------------------------------
Message: 7
Date: Sat, 21 Nov 2009 17:43:29 -0500
From: Isaac Dupree <[email protected]>
Subject: Re: [Haskell-beginners] Type classes and synonyms
To: Philip Scott <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Philip Scott wrote:
> Thanks John,
>
>> Every module can have its own definition for each name, such as the
>> operator (+). So in your module (eg. module Main, or module
>> DateValueSeries), you can go ahead and define your own (+). The major
>> caveat is making sure you don't conflict with the default (+), which lives
>> in module Prelude, which is normally automatically brought into scope.
>
> That actually quite nicely solves the problem... it feels almost a little too
> easy, after spending the evening getting my mind wrapped up with Arrows :)
why has no one mentioned: you most likely don't need to understand
Arrows? I'm pretty good with Haskell, and Arrows are still somewhat
confusing to me. Why? Most problems I've worked with in Haskell have
had more-idiomatic solutions than Arrows. (examples include: Monad;
Functor; Applicative; just plain functions; plain old lack of type-class
abstraction.) It's not so easy or useful to understand any
abstraction/class without using at least two or three useful
examples/instances of it first.
-Isaac
------------------------------
Message: 8
Date: Sat, 21 Nov 2009 21:07:35 -0200
From: Felipe Lessa <[email protected]>
Subject: Re: [Haskell-beginners] Type classes and synonyms
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Sat, Nov 21, 2009 at 05:43:29PM -0500, Isaac Dupree wrote:
> why has no one mentioned: you most likely don't need to understand
> Arrows? I'm pretty good with Haskell, and Arrows are still somewhat
> confusing to me. Why? Most problems I've worked with in Haskell
> have had more-idiomatic solutions than Arrows. (examples include:
> Monad; Functor; Applicative; just plain functions; plain old lack of
> type-class abstraction.) It's not so easy or useful to understand
> any abstraction/class without using at least two or three useful
> examples/instances of it first.
In defence of my solution, I haven't really used the power of the
arrows. The "problem" is that the quite useful functions first,
second, (***) and (&&&) are defined within Control.Arrow.
Cheers, :)
--
Felipe.
------------------------------
Message: 9
Date: Sun, 22 Nov 2009 09:11:21 +1000
From: Tony Morris <[email protected]>
Subject: Re: [Haskell-beginners] Type classes and synonyms
To: Isaac Dupree <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
If you don't yet understand Arrows, then what compels you to conclude
that there are more idiomatic solutions (than what you don't yet
understand)?
Just sayin'
Isaac Dupree wrote:
> Philip Scott wrote:
>> Thanks John,
>>
>>> Every module can have its own definition for each name, such as the
>>> operator (+). So in your module (eg. module Main, or module
>>> DateValueSeries), you can go ahead and define your own (+). The major
>>> caveat is making sure you don't conflict with the default (+),
>>> which lives
>>> in module Prelude, which is normally automatically brought into scope.
>>
>> That actually quite nicely solves the problem... it feels almost a
>> little too easy, after spending the evening getting my mind wrapped
>> up with Arrows :)
>
> why has no one mentioned: you most likely don't need to understand
> Arrows? I'm pretty good with Haskell, and Arrows are still somewhat
> confusing to me. Why? Most problems I've worked with in Haskell have
> had more-idiomatic solutions than Arrows. (examples include: Monad;
> Functor; Applicative; just plain functions; plain old lack of
> type-class abstraction.) It's not so easy or useful to understand any
> abstraction/class without using at least two or three useful
> examples/instances of it first.
>
> -Isaac
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
--
Tony Morris
http://tmorris.net/
------------------------------
Message: 10
Date: Sun, 22 Nov 2009 10:52:51 +1100
From: Ben Lippmeier <[email protected]>
Subject: Re: [Haskell-beginners] Re: Is Haskell for me?
To: Jon Harrop <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
On 22/11/2009, at 5:02 , Jon Harrop wrote:
>
>> By the above reasoning, if I were to run any program
>> using arrays on a system with a two space garbage collector (which copies
>> all live objects during each GC) I could say the worst case algorithmic
>> complexity was O(n). That doesn't sound right.
>
> Can you write a program that demonstrates this effect as I did?
I believe your numbers, but I don't have a F# install to test against ATM.
> Suffice to say, Haskell is nowhere near being in the ballpark of C++'s
> performance for basic functionality like dictionaries and sorting.
Sorry, I wasn't trying to start a pissing match. I just wanted to know what the
issue was so I could avoid it in my own programs.
Thanks!
Ben.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20091121/76b2abd0/attachment.html
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 17, Issue 22
*****************************************