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: List.sort (John Dorsey)
2. Re: The Applicative instance for ((->) a) (Heinrich Apfelmus)
3. Re: List.sort (Patrick LeBoutillier)
4. Re: List.sort (Chadda? Fouch?)
5. Re: List.sort (Patrick LeBoutillier)
6. Re: List.sort (Geoffrey Marchant)
7. external sort (Keith Sheppard)
8. Re: external sort (Felipe Lessa)
----------------------------------------------------------------------
Message: 1
Date: Sat, 11 Jul 2009 09:17:04 -0400
From: John Dorsey <[email protected]>
Subject: Re: [Haskell-beginners] List.sort
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
I sent this only to Patrick by mistake. Sorry for the duplicate, Patrick.
--
Patrick,
> Ord a => [a] -> [a]
>
> I don't understand how this type can allow it to sort pairs:
>
> Prelude> :m +List
> Prelude List> sort [(1, "1"), (3, "3"), (2, "2")]
> [(1,"1"),(2,"2"),(3,"3")]
>
> How can a pair by of type "Ord a"? Is it a rule that the first element
> is automatically used?
"Ord a" isn't really the type of a pair... it's a type *constraint* on the
argument to the sort function, which is otherwise any type "a".
So it means List.sort can be applied to any type "a" which satisfies "Ord a".
But what does that mean? It means that there is an instance for the
typeclass Ord for whatever type is given to Listsort.
In the case of pairs, it's exactly as you guessed... the leftmost parts are
compared first. This is so because somewhere there's an "instance Ord (a,b)"
that defines how to compare pairs, and it does it that way (left-to-right).
(And this generalizes to tuples bigger than pairs, up to some
compiler-specific limit.)
Does this make sense?
John
------------------------------
Message: 2
Date: Sat, 11 Jul 2009 17:53:20 +0200
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: The Applicative instance for ((->) a)
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Ian Duncan wrote:
> Hey folks, I understand most of what is going on with the applicative
> class, but I can't figure out why this instance is useful:
> "instance Applicative ((->) a) where..."
>
> Can anyone offer some intuition into how this is could be used?
As hinted to in the paper on applicative functors,
Applicative programming with effects
Conor McBride, Ross Paterson.
http://strictlypositive.org/IdiomLite.pdf
the instance functors are the S and K combinators.
http://en.wikipedia.org/wiki/SKI_combinator_calculus
Regards,
apfelmus
--
http://apfelmus.nfshost.com
------------------------------
Message: 3
Date: Sat, 11 Jul 2009 11:57:10 -0400
From: Patrick LeBoutillier <[email protected]>
Subject: Re: [Haskell-beginners] List.sort
To: John Dorsey <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
> Patrick,
>
>> Ord a => [a] -> [a]
>>
>> I don't understand how this type can allow it to sort pairs:
>>
>> Prelude> :m +List
>> Prelude List> sort [(1, "1"), (3, "3"), (2, "2")]
>> [(1,"1"),(2,"2"),(3,"3")]
>>
>> How can a pair by of type "Ord a"? Is it a rule that the first element
>> is automatically used?
>
> "Ord a" isn't really the type of a pair... it's a type *constraint* on the
> argument to the sort function, which is otherwise any type "a".
>
> So it means List.sort can be applied to any type "a" which satisfies "Ord a".
> But what does that mean? It means that there is an instance for the
> typeclass Ord for whatever type is given to Listsort.
>
> In the case of pairs, it's exactly as you guessed... the leftmost parts are
> compared first. This is so because somewhere there's an "instance Ord (a,b)"
> that defines how to compare pairs, and it does it that way (left-to-right).
> (And this generalizes to tuples bigger than pairs, up to some
> compiler-specific limit.)
>
> Does this make sense?
Yes, perfectly. I guess you just have to know about it... :)
>
> John
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
--
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada
------------------------------
Message: 4
Date: Sat, 11 Jul 2009 19:13:30 +0200
From: Chadda? Fouch? <[email protected]>
Subject: Re: [Haskell-beginners] List.sort
To: Patrick LeBoutillier <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Sat, Jul 11, 2009 at 5:57 PM, Patrick
LeBoutillier<[email protected]> wrote:
>> Does this make sense?
>
> Yes, perfectly. I guess you just have to know about it... :)
>
Well, it's the lexicographic order, the most "natural", in any case
the most used order for tuples, so it would be strange to have other
expectations by default
Of course, the mechanism by which this work is interesting by itself.
--
Jedaï
------------------------------
Message: 5
Date: Sat, 11 Jul 2009 14:25:34 -0400
From: Patrick LeBoutillier <[email protected]>
Subject: Re: [Haskell-beginners] List.sort
To: Chadda? Fouch? <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On Sat, Jul 11, 2009 at 1:13 PM, Chaddaï Fouché<[email protected]> wrote:
> On Sat, Jul 11, 2009 at 5:57 PM, Patrick
> LeBoutillier<[email protected]> wrote:
>>> Does this make sense?
>>
>> Yes, perfectly. I guess you just have to know about it... :)
>>
>
> Well, it's the lexicographic order, the most "natural", in any case
> the most used order for tuples, so it would be strange to have other
> expectations by default
>
> Of course, the mechanism by which this work is interesting by itself.
Really interesting in fact. It shows how generic these concepts really
are. But it wasn't obvious to me that a pair could be an instance of
Ord.
This kind of gives you a clue:
Prelude> :info ()
data () = () -- Defined in GHC.Unit
instance Bounded () -- Defined in GHC.Enum
instance Enum () -- Defined in GHC.Enum
instance Eq () -- Defined in Data.Tuple
instance Ord () -- Defined in Data.Tuple
instance Read () -- Defined in GHC.Read
instance Show () -- Defined in GHC.Show
but is there a way to do the equivalent of:
Prelude> :info (a,b)
or
Prelude> :info (Int,String)
?
Patrick
>
> --
> Jedaï
>
--
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada
------------------------------
Message: 6
Date: Sat, 11 Jul 2009 13:41:04 -0600
From: Geoffrey Marchant <[email protected]>
Subject: Re: [Haskell-beginners] List.sort
To: Patrick LeBoutillier <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Try
Prelude> :info (,)
data (,) a b = (,) a b -- Defined in GHC.Tuple
instance (Bounded a, Bounded b) => Bounded (a, b)
-- Defined in GHC.Enum
instance (Eq a, Eq b) => Eq (a, b) -- Defined in Data.Tuple
instance (Ord a, Ord b) => Ord (a, b) -- Defined in Data.Tuple
instance (Read a, Read b) => Read (a, b) -- Defined in GHC.Read
instance (Show a, Show b) => Show (a, b) -- Defined in GHC.Show
On Sat, Jul 11, 2009 at 12:25 PM, Patrick LeBoutillier <
[email protected]> wrote:
> On Sat, Jul 11, 2009 at 1:13 PM, Chaddaï Fouché<[email protected]>
> wrote:
> > On Sat, Jul 11, 2009 at 5:57 PM, Patrick
> > LeBoutillier<[email protected]> wrote:
> >>> Does this make sense?
> >>
> >> Yes, perfectly. I guess you just have to know about it... :)
> >>
> >
> > Well, it's the lexicographic order, the most "natural", in any case
> > the most used order for tuples, so it would be strange to have other
> > expectations by default
> >
> > Of course, the mechanism by which this work is interesting by itself.
>
> Really interesting in fact. It shows how generic these concepts really
> are. But it wasn't obvious to me that a pair could be an instance of
> Ord.
>
> This kind of gives you a clue:
>
> Prelude> :info ()
> data () = () -- Defined in GHC.Unit
> instance Bounded () -- Defined in GHC.Enum
> instance Enum () -- Defined in GHC.Enum
> instance Eq () -- Defined in Data.Tuple
> instance Ord () -- Defined in Data.Tuple
> instance Read () -- Defined in GHC.Read
> instance Show () -- Defined in GHC.Show
>
> but is there a way to do the equivalent of:
>
> Prelude> :info (a,b)
> or
> Prelude> :info (Int,String)
>
> ?
>
> Patrick
>
> >
> > --
> > Jedaï
> >
>
>
>
> --
> =====================
> Patrick LeBoutillier
> Rosemère, Québec, Canada
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090711/b50fca57/attachment-0001.html
------------------------------
Message: 7
Date: Sat, 11 Jul 2009 20:40:10 -0400
From: Keith Sheppard <[email protected]>
Subject: [Haskell-beginners] external sort
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
I'm reworking external sort to meet the needs of my app and I'm
running into some trouble that I was hoping to get some advice on. I'm
asking a lot of questions here so don't feel obligated to answer them
all if you have input on one point:
The code is here: http://tinyurl.com/extsort
1) The sort gives the correct result, but when I tried to sort very
large files (~4 Gb) I got this message:
tssql: /var/folders/Tl/TlS1rTCyFpWU9s-IsNFkdE+++TI/-Tmp-/sort4106.txt:
openBinaryFile: resource exhausted (Too many open files)
I tried to be careful about limiting the number of open file handles
but I must have done something wrong. Do you see where I'm leaking
file handles?
2) I'm guessing there's a smarter way to do unwrapMonads?
3) I'd like to create a function like BS.hGetContents which lazily
reads the ByteString but in addition to closing the file after the
last byte is read I want it to delete the file that I'm reading from.
Like hGetContentsThenDelete. It seems like
http://hackage.haskell.org/package/lazyio but it isn't clear to me how
I would do this
I cant do
> LazyIO.run $ do
> str <- BS.hGetContents file
> removeFile file
> return str
can I? I assume that would close the file too soon
4) Is there any other wacky stuff in my code that I should change?
I told you it was a lot :-) Thanks!
-Keith
--
keithsheppard.name
------------------------------
Message: 8
Date: Sat, 11 Jul 2009 22:59:19 -0300
From: Felipe Lessa <[email protected]>
Subject: Re: [Haskell-beginners] external sort
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Sat, Jul 11, 2009 at 08:40:10PM -0400, Keith Sheppard wrote:
> 2) I'm guessing there's a smarter way to do unwrapMonads?
unwrapMonads is actually sequence :), see [1].
[1]
http://hackage.haskell.org/packages/archive/base/latest/doc/html/src/Control-Monad.html#sequence
--
Felipe.
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 13, Issue 7
****************************************