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: Haskell vs Clean (speed) (Benjamin L.Russell)
2. Re: Re: Haskell vs Clean (speed) (Daniel Carrera)
3. Re: Haskell vs Clean (speed) (Benjamin L.Russell)
4. Re: Searching Maybe lists (Heinrich Apfelmus)
5. Re: Searching Maybe lists (Thomas Friedrich)
6. Re: Searching Maybe lists (Daniel Fischer)
7. Re: Re: Searching Maybe lists (aditya siram)
8. Re: Searching Maybe lists (aditya siram)
----------------------------------------------------------------------
Message: 1
Date: Tue, 19 May 2009 14:02:25 +0900
From: Benjamin L.Russell <[email protected]>
Subject: [Haskell-beginners] Re: Haskell vs Clean (speed)
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Sun, 03 May 2009 18:06:33 +0200, Daniel Carrera
<[email protected]> wrote:
>I can't subscribe to Haskell-Cafe, so I'll post here.
Thank you for your post.
>Here I compare Haskell, Clean, OCaml, Lisp SBCL, C# Mono and
>Fortran because they are all in the same ball mark:
Which implementation of Fortran? According to "Fortran - Wikipedia,
the free encyclopedia" (see http://en.wikipedia.org/wiki/Fortran),
there are Absoft, Cray, GFortran, G95, Intel, Lahey/Fujitsu, Open
Watcom, Pathscale, PGI, Silverfrost, Sun, XL Fortran, Visual Fortran,
and other implementations.
>* There are no results for OCaml for 32-bit.
I'll be sure to ask Jon Harrop about that the next time he talks about
OCaml and speed comparisons ;).
Incidentally, why can't you also subscribe to Haskell-Cafe?
-- Benjamin L. Russell
--
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^
------------------------------
Message: 2
Date: Tue, 19 May 2009 08:02:42 +0200
From: Daniel Carrera <[email protected]>
Subject: Re: [Haskell-beginners] Re: Haskell vs Clean (speed)
To: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Benjamin L.Russell wrote:
> Incidentally, why can't you also subscribe to Haskell-Cafe?
Eventually I found that somehow I couldn't get any emails at all from
the Haskell server, but the problem magically fixed itself after several
hours, so I did subscribe to haskell-cafe and there was a short thread
about Haskell vs Clean. The message I got out of it is that it is very
difficult to draw any conclusions from the Debian benchmark because
there are more Haskell people willing to optimize the Haskell code.
Daniel.
------------------------------
Message: 3
Date: Tue, 19 May 2009 16:21:49 +0900
From: Benjamin L.Russell <[email protected]>
Subject: [Haskell-beginners] Re: Haskell vs Clean (speed)
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Tue, 19 May 2009 08:02:42 +0200, Daniel Carrera
<[email protected]> wrote:
>Benjamin L.Russell wrote:
>> Incidentally, why can't you also subscribe to Haskell-Cafe?
>
>Eventually I found that somehow I couldn't get any emails at all from
>the Haskell server, but the problem magically fixed itself after several
>hours, so I did subscribe to haskell-cafe and there was a short thread
>about Haskell vs Clean. The message I got out of it is that it is very
>difficult to draw any conclusions from the Debian benchmark because
>there are more Haskell people willing to optimize the Haskell code.
Yes, I just read that thread ("[Haskell-cafe] Haskell vs Clean (speed
comparison)" at
http://www.mail-archive.com/[email protected]/msg58988.html).
Based on the discussions there, there seem to be two problems with
this benchmark. In reference to Bulat Ziganshin's comments in that
thread,
On Sun, 3 May 2009 22:42:21 +0400, Bulat Ziganshin
<[email protected]> wrote:
>Hello Daniel,
>
>Sunday, May 3, 2009, 10:24:52 PM, you wrote:
>
>> 32-bit sing core [1]: Lisp, Fortran
>
>:) this test measures speed of some programs, not "languages".
>results are depends mainly on bundled libraries and RTS. by no means
>it demonstrates speed of compiler-generated code of carefully-written
>program what is typically considered as "language speed". the reasons
>are:
>
>1) C++ people (and probably Fortran too) aren't so interested in
>making fastest possible programs as Haskell community. it becomes
>popular a few years ago, you can find that Haskell becomes several
>faster at average since then, which doesn't reflect actual
>improvements in GHC code generation (10-20%)
What is the reason for this phenomenon, though? If participants don't
optimize their programs, then what is the use of the benchmark?
>2) Most programs there depend on speed of libraries. Moreover, there
>is limitation that it should be *bundled* libraries, so results
>greatly depends on what currently included in one compiler or another
Is there a specific reason that the libraries need to be bundled?
>3) it's prohibited to write your own fast code if bundled library is
>too slow (for example, because it's too general)
Again, this seems to give an advantage to programming languages with a
preponderance of optimized bundled libraries.
Based on the above arguments, it seems as if this benchmark does not
really compare programming languages; rather, it seems to compare
combinations of programming languages and their bundled libraries and
communities. But then what happens if you have a great programming
language with few optimized libraries and a small and relatively
inactive community?
-- Benjamin L. Russell
--
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^
------------------------------
Message: 4
Date: Tue, 19 May 2009 10:05:00 +0200
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: Searching Maybe lists
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
aditya siram wrote:
> Hi all,
> I would like to define a function that takes a list and a function that
> evaluates each member of the list to a Maybe value and output the first
> element in the list that evaluates to 'Just y', or 'Nothing' once the list
> has been completely processed. So something like:
>
> findMaybe :: [a] -> (a -> Maybe b) -> Maybe b
>
> The problem is that I don't want it to go through the entire list, but
> short-circuit when it hits a 'Just ...'. So far I have:
>
> orMaybe :: Maybe a -> Maybe a -> Maybe a
> orMaybe m1 m2 = case (m1,m2) of
> (_, Just a) -> Just a
> (Just a, _) -> Just a
> _ -> Nothing
>
> findMaybe :: [a] -> (a -> Maybe b) -> Maybe b
> findMaybe as f = foldr (\a sofar -> sofar `orMaybe` (f a)) Nothing as
>
>
> 'findMaybe', as far as I can tell, traverses the entire input list
Thanks to lazy evaluation, this is not necessarily the case, see also
http://en.wikibooks.org/wiki/Haskell/Performance_Introduction#Time
You will have to write orMaybe as
orMaybe Nothing y = y
orMaybe x _ = x
though. (By the way, your original code for orMaybe doesn't seem to do
what you want.) This function has already been implemented for you, it's
called
mplus
Regards,
apfelmus
--
http://apfelmus.nfshost.com
------------------------------
Message: 5
Date: Tue, 19 May 2009 09:39:16 -0400
From: Thomas Friedrich <[email protected]>
Subject: Re: [Haskell-beginners] Searching Maybe lists
To: aditya siram <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Hi Aditya,
Please try the following:
findJust :: (Eq a) => [Maybe a] -> Maybe a
findJust xs = case (dropWhile (==Nothing) xs) of
[] -> Nothing
cs -> head cs
yourFunction :: (Eq b) => (a -> Maybe b) -> [a] -> Maybe b
yourFunction f xs = findJust (map f xs)
It only uses functions from the Prelude, and as Haskell evaluates lazy,
it just does exactly what you wants.
Happy Hacking,
Thomas
aditya siram wrote:
> Hi all,
> I would like to define a function that takes a list and a function
> that evaluates each member of the list to a Maybe value and output the
> first element in the list that evaluates to 'Just y', or 'Nothing'
> once the list has been completely processed. So something like:
>
> findMaybe :: [a] -> (a -> Maybe b) -> Maybe b
>
> The problem is that I don't want it to go through the entire list, but
> short-circuit when it hits a 'Just ...'. So far I have:
>
> orMaybe :: Maybe a -> Maybe a -> Maybe a
> orMaybe m1 m2 = case (m1,m2) of
> (_, Just a) -> Just a
> (Just a, _) -> Just a
> _ -> Nothing
>
> findMaybe :: [a] -> (a -> Maybe b) -> Maybe b
> findMaybe as f = foldr (\a sofar -> sofar `orMaybe` (f a)) Nothing as
>
> 'findMaybe', as far as I can tell, traverses the entire input list
> which is undesirable for long lists. How can I fix it?
>
> Curiously, the regular 'Data.List.find' function that applies a
> Boolean predicate to each member of the list also seems to first
> traverse the entire list using 'filter' and then grabs the head of the
> result.
>
> Thanks ...
> -deech
> ------------------------------------------------------------------------
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 6
Date: Tue, 19 May 2009 17:02:28 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Searching Maybe lists
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Am Dienstag 19 Mai 2009 15:39:16 schrieb Thomas Friedrich:
> Hi Aditya,
>
> Please try the following:
>
> findJust :: (Eq a) => [Maybe a] -> Maybe a
> findJust xs = case (dropWhile (==Nothing) xs) of
> [] -> Nothing
> cs -> head cs
>
> yourFunction :: (Eq b) => (a -> Maybe b) -> [a] -> Maybe b
> yourFunction f xs = findJust (map f xs)
>
> It only uses functions from the Prelude, and as Haskell evaluates lazy,
> it just does exactly what you wants.
No need for the Eq constraint,
findJust xs = case dropWhile isNothing xs of
[] -> Nothing
(x:_) -> x
isNothing could be imported from Data.Maybe or defined as
isNothing Nothing = True
isNothing _ = False
if you don't want the import.
Another method to define findJust is
import Data.Maybe
findJust = listToMaybe . catMaybes
or
import Control.Monad
findJust = msum
So for the original problem, we could use any of
findMaybe :: [a] -> (a -> Maybe b) -> Maybe b
findMaybe xs f = msum $ map f xs
-- this indicates that the parameter order should be different
findMaybe xs f = foldr mplus Nothing (map f xs)
findMaybe xs f = listToMaybe . catMaybes $ map f xs
findMaybe xs f = head (dropWhile isNothing (map f xs) ++ [Nothing])
findMaybe xs f = find isJust (map f xs) >>= id
I find the first two best, but they bring Control.Monad into the game, if one
wants to
avoid that, I'd recommend defining 'mplus' for Maybe oneself,
orMaybe m1@(Just _) _ = m1
orMaybe _ m2 = m2
findMaybe xs f = foldr orMaybe Nothing (map f xs).
>
> Happy Hacking,
> Thomas
>
> aditya siram wrote:
> > Hi all,
> > I would like to define a function that takes a list and a function
> > that evaluates each member of the list to a Maybe value and output the
> > first element in the list that evaluates to 'Just y', or 'Nothing'
> > once the list has been completely processed. So something like:
> >
> > findMaybe :: [a] -> (a -> Maybe b) -> Maybe b
> >
> > The problem is that I don't want it to go through the entire list, but
> > short-circuit when it hits a 'Just ...'. So far I have:
> >
> > orMaybe :: Maybe a -> Maybe a -> Maybe a
> > orMaybe m1 m2 = case (m1,m2) of
> > (_, Just a) -> Just a
> > (Just a, _) -> Just a
> > _ -> Nothing
> >
> > findMaybe :: [a] -> (a -> Maybe b) -> Maybe b
> > findMaybe as f = foldr (\a sofar -> sofar `orMaybe` (f a)) Nothing as
> >
> > 'findMaybe', as far as I can tell, traverses the entire input list
> > which is undesirable for long lists. How can I fix it?
> >
> > Curiously, the regular 'Data.List.find' function that applies a
> > Boolean predicate to each member of the list also seems to first
> > traverse the entire list using 'filter' and then grabs the head of the
> > result.
> >
> > Thanks ...
> > -deech
------------------------------
Message: 7
Date: Tue, 19 May 2009 11:02:50 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] Re: Searching Maybe lists
To: Heinrich Apfelmus <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
>
>
>
> You will have to write orMaybe as
>
> orMaybe Nothing y = y
> orMaybe x _ = x
>
> though. (By the way, your original code for orMaybe doesn't seem to do
> what you want.) This function has already been implemented for you, it's
> called
>
> mplus
My function 'orMaybe' takes two arguments m1 m2, if one of them is Nothing,
it returns Nothing, if m1 is Just , it returns m1, if m2 is Just, it returns
m2. This seems to be what I want. Why is this incorrect?
However, your function 'orMaybe' is much more concise and elegant.
thanks ...
-deech
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20090519/3d8e6f67/attachment-0001.html
------------------------------
Message: 8
Date: Tue, 19 May 2009 11:05:09 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] Searching Maybe lists
To: Thomas Friedrich <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Awesome! This seems to be an analog of the Data.List.find function. I
originally didn't implement mine this way because I thought it went through
the entire list, but I was obviously mistaken!
Thanks for your help!
-deech
On Tue, May 19, 2009 at 8:39 AM, Thomas Friedrich <[email protected]> wrote:
> Hi Aditya,
>
> Please try the following:
>
> findJust :: (Eq a) => [Maybe a] -> Maybe a
> findJust xs = case (dropWhile (==Nothing) xs) of
> [] -> Nothing
> cs -> head cs
>
> yourFunction :: (Eq b) => (a -> Maybe b) -> [a] -> Maybe b
> yourFunction f xs = findJust (map f xs)
>
> It only uses functions from the Prelude, and as Haskell evaluates lazy, it
> just does exactly what you wants.
>
> Happy Hacking,
> Thomas
>
>
>
> aditya siram wrote:
>
>> Hi all,
>> I would like to define a function that takes a list and a function that
>> evaluates each member of the list to a Maybe value and output the first
>> element in the list that evaluates to 'Just y', or 'Nothing' once the list
>> has been completely processed. So something like:
>>
>> findMaybe :: [a] -> (a -> Maybe b) -> Maybe b
>>
>> The problem is that I don't want it to go through the entire list, but
>> short-circuit when it hits a 'Just ...'. So far I have:
>>
>> orMaybe :: Maybe a -> Maybe a -> Maybe a
>> orMaybe m1 m2 = case (m1,m2) of
>> (_, Just a) -> Just a
>> (Just a, _) -> Just a
>> _ -> Nothing
>> findMaybe :: [a] -> (a -> Maybe b) -> Maybe
>> b
>> findMaybe as f = foldr (\a sofar -> sofar `orMaybe` (f a)) Nothing as
>>
>> 'findMaybe', as far as I can tell, traverses the entire input list which
>> is undesirable for long lists. How can I fix it?
>>
>> Curiously, the regular 'Data.List.find' function that applies a Boolean
>> predicate to each member of the list also seems to first traverse the entire
>> list using 'filter' and then grabs the head of the result.
>>
>> Thanks ...
>> -deech
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> 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/20090519/7b5b1ad2/attachment.html
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 11, Issue 13
*****************************************