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: Selecting a GUI toolkit (Heinrich Apfelmus)
2. Re: Re: Selecting a GUI toolkit (Thomas Davie)
3. Re: Parsec tutorial (Keith Sheppard)
4. Haskell vs Clean (speed) (Daniel Carrera)
5. Re: Haskell vs Clean (speed) (Magnus Therning)
6. Polymorphism question from an OO-speaking newbie (Joel Neely)
7. Re: Polymorphism question from an OO-speaking newbie
(Jan Jakubuv)
8. Re: Polymorphism question from an OO-speaking newbie
(Jan Jakubuv)
9. Re: Polymorphism question from an OO-speaking newbie
(Ertugrul Soeylemez)
----------------------------------------------------------------------
Message: 1
Date: Sat, 02 May 2009 09:39:03 +0200
From: Heinrich Apfelmus <[email protected]>
Subject: [Haskell-beginners] Re: Selecting a GUI toolkit
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Daniel Carrera wrote:
> Anyways, to bring back some context into the discussion. We were talking
> about whether WX is better than X11+Gtk on Mac. I am confident that it is.
I concur.
What has put me off of cross-platform GUIs so far is probably not even
the appearance, but rather that the programs I've seen don't work
correctly: weird behavior, drawing bugs when updating the screen,
sluggishness, and crashes. The Gtk+X11 ones (Gimp, Inkscape) usually
work better than those who try to use a native toolkit. Hopefully,
Haskell easily avoids these kinds of problems. :)
Regards,
apfelmus
--
http://apfelmus.nfshost.com
------------------------------
Message: 2
Date: Sat, 2 May 2009 10:22:32 +0200
From: Thomas Davie <[email protected]>
Subject: Re: [Haskell-beginners] Re: Selecting a GUI toolkit
To: Daniel Carrera <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes
On 1 May 2009, at 22:20, Daniel Carrera wrote:
> Heinrich Apfelmus wrote:
>>> More importantly, I'm not sure that a different cross-platform
>>> toolkit would do a better job.
>> True, that. It's just that this doesn't mean that wxWidgets does a
>> very
>> good job.
>
> Well, "very good job" is a really fuzzy term. Based on the very
> limited set of screen shots that I have seen, I think WX does well
> enough for anyone but a pedant (and you disagree, I know).
Unfortunately for you, many Mac users are pedants - they expect
everything to be exactly in place, perfectly.
Bob
------------------------------
Message: 3
Date: Sat, 2 May 2009 21:27:18 -0400
From: Keith Sheppard <[email protected]>
Subject: Re: [Haskell-beginners] Parsec tutorial
To: Patrick LeBoutillier <[email protected]>,
[email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi Patrick,
This isn't what you asked for but it may be useful to you. I've
created a parsec based SQL parser for my "TxtSushi" command-line
program. It's still pretty early in development but it does parse a
subset of the SELECT grammar. The project's page is
http://keithsheppard.name/txt-sushi/index.html
Keith
------------------------------
Message: 4
Date: Sun, 03 May 2009 18:06:33 +0200
From: Daniel Carrera <[email protected]>
Subject: [Haskell-beginners] Haskell vs Clean (speed)
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Hi,
I can't subscribe to Haskell-Cafe, so I'll post here.
I found something interesting. "General wisdom" is that Clean (or OCaml)
is faster than Haskell. The claim is often followed by a link to the
Debian shootout. But on closer inspection, I question this conclusion.
The Debian shoot out actually has four sets of benchmarks:
1) Intel 32-bit one core.
2) Intel 32-bit quad-core.
3) Intel 64-bit one core.
4) Intel 64-bit quad-core.
It turns out that Clean is only faster for (1). For the others, Haskell
is faster. Here I compare Haskell, Clean, OCaml, Lisp SBCL, C# Mono and
Fortran because they are all in the same ball mark:
32-bit sing core [1]: Lisp, Fortran, Clean, Haskell, C# Mono.
32-bit quad-core [2]: Haskell, C# Mono, Lisp, Clean, Fortran.
64-bit sing core [3]: Fortran, OCaml, Haskell, Clean, C# Mono, Lisp.
64-bit quad-core [4]: Haskell, OCaml, Lisp, C# Mono, Fortran, Clean.
Notes:
* The order is "fast language first".
* There are no results for OCaml for 32-bit.
* "Lisp" is "List SCBL" whatever that is.
Tentative conclusions:
1) Haskell makes very good use of multiple cores. It smokes Clean.
2) For single core, they are neck and neck. Whether Clean is faster
depends non the architecture.
What do you think?
Daniel.
P.S.
[1]http://shootout.alioth.debian.org/u32/benchmark.php?test=all&lang=all&d=data&ghc=on&ocaml=on&sbcl=on&csharp=on&ifc=on&clean=on&calc=calculate&box=1
[2]http://shootout.alioth.debian.org/u32q/benchmark.php?test=all&lang=all&d=data&ghc=on&ocaml=on&sbcl=on&csharp=on&ifc=on&clean=on&calc=calculate&box=1
[3]http://shootout.alioth.debian.org/u64/benchmark.php?test=all&lang=all&d=data&ghc=on&ocaml=on&sbcl=on&csharp=on&ifc=on&clean=on&calc=calculate&box=1
[4]http://shootout.alioth.debian.org/u64q/benchmark.php?test=all&lang=all&d=data&ghc=on&ocaml=on&sbcl=on&csharp=on&ifc=on&clean=on&calc=calculate&box=1
------------------------------
Message: 5
Date: Sun, 03 May 2009 21:11:52 +0100
From: Magnus Therning <[email protected]>
Subject: Re: [Haskell-beginners] Haskell vs Clean (speed)
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Daniel Carrera wrote:
[..]
> * "Lisp" is "List SCBL" whatever that is.
That should probably be SBCL, as in Steel Bank Common Lisp. No?
/M
--
Magnus Therning (OpenPGP: 0xAB4DFBA4)
magnusï¼ therningï¼org Jabber: magnusï¼ therningï¼org
http://therning.org/magnus identi.ca|twitter: magthe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: OpenPGP digital signature
Url :
http://www.haskell.org/pipermail/beginners/attachments/20090503/b7f423e4/signature-0001.bin
------------------------------
Message: 6
Date: Mon, 4 May 2009 10:34:09 -0500
From: Joel Neely <[email protected]>
Subject: [Haskell-beginners] Polymorphism question from an OO-speaking
newbie
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Short version: Is it possible/reasonable to define a single function
that accepts a single string or a list of strings (in which case it
maps the single-string "flavor" over the list)?
Longer version: Thus far I know that Haskell allows me to define a
function on a single string, then define another function that maps
the first one across a list of strings, as in:
*Main> let quote1 s = "\"" ++ s ++ "\""
*Main> "Quux said " ++ quote1 "foo" ++ " loudly"
"Quux said \"foo\" loudly"
*Main> let quote = map quote1
*Main> quote ["foo", "baz", "bletch"]
["\"foo\"","\"baz\"","\"bletch\""]
(BTW, is it standard terminology to say that quote lifts quote1 to lists?)
In the above I have different names for the two functions. OO
languages such as Java allow me to overload quote to accept either
String or List<String> (and return the same type). AFAICT, Haskell's
parametric polymorphism allows me to define functions (e.g. length)
which deal with "listness" concepts indifferent to the type contained
by the list.
Am I missing something, or should I admit to OO wrongheadedness and
accept that my inability to write a single declaration unifying:
quote :: String -> String
quote :: [String] -> [String]
is an emphatic clue that I should change my expectations?
Thanks in advance for any enlightenment shed my way!
-jn-
--
Beauty of style and harmony and grace and good rhythm depend on
simplicity. - Plato
------------------------------
Message: 7
Date: Mon, 4 May 2009 17:23:59 +0100
From: Jan Jakubuv <[email protected]>
Subject: Re: [Haskell-beginners] Polymorphism question from an
OO-speaking newbie
To: Joel Neely <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Mon, May 04, 2009 at 10:34:09AM -0500, Joel Neely wrote:
> Short version: Is it possible/reasonable to define a single function
> that accepts a single string or a list of strings (in which case it
> maps the single-string "flavor" over the list)?
>
Hi Joel,
you are looking for type classes (http://haskell.org/tutorial/classes.html).
They allow you to use the same function name for different types. This is
called ``ad-hoc'' polymorphism and you can define different implementation
of the overloaded function for different types (which is your case). Haskell
also support ``parametric'' polymorphism which can be used when you have the
same implementation for different types (like the function `head` which
returns the first member of a list independently on the type of elements).
Try the following:
{-# OPTIONS -fglasgow-exts #-}
quoteS s = "\"" ++ s ++ "\""
quoteL l = map quoteS l
class Quatable q where
quote :: q -> q
instance Quatable String where
quote s = "\"" ++ s ++ "\""
instance Quatable [String] where
quote = map quote
Then you can use it as follows:
*Main> "Quux said " ++ quote "foo" ++ " loudly"
"Quux said \"foo\" loudly"
*Main> quote ["foo", "baz", "bletch"]
["\"foo\"","\"baz\"","\"bletch\""]
Don't forget the line `{-# OPTIONS -fglasgow-exts #-}` which enables some
features of GHC you need for this example (but not necessarily for all
examples using type classes). Alternatively you can use the line
{-# LANGUAGE TypeSynonymInstances,FlexibleInstances #-}
which lists necessary extensions explicitly.
Sincerely,
Jan.
--
Heriot-Watt University is a Scottish charity
registered under charity number SC000278.
------------------------------
Message: 8
Date: Mon, 4 May 2009 17:29:26 +0100
From: Jan Jakubuv <[email protected]>
Subject: Re: [Haskell-beginners] Polymorphism question from an
OO-speaking newbie
To: Joel Neely <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Mon, May 04, 2009 at 05:23:59PM +0100, Jan Jakubuv wrote:
>
> Try the following:
>
> {-# OPTIONS -fglasgow-exts #-}
>
> quoteS s = "\"" ++ s ++ "\""
> quoteL l = map quoteS l
I forgot to say that the functions `quoteS` and `quoteL` are just for
illustration. You can miss them.
Jan.
--
Heriot-Watt University is a Scottish charity
registered under charity number SC000278.
------------------------------
Message: 9
Date: Mon, 4 May 2009 18:34:28 +0200
From: Ertugrul Soeylemez <[email protected]>
Subject: [Haskell-beginners] Re: Polymorphism question from an
OO-speaking newbie
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII
Hello Joel,
the polymorphism concept in Haskell's type system is not the same as
OOP's polymorphism. OOP polymorphism allows you to build abstract
interfaces, whereas Haskell's polymorphism allows you to generalize both
statements and functionality.
There is no way to 'select' String and [String], as those two types have
almost nothing in common. If you find types that have something in
common, you can express it. "Having something in common" always means:
there is a set of functions, which is defined for both.
For example, the two types Integer and Float have in common that they
are numeric types. Technically this means that (+), (-), (*) and a few
other functions are defined for them. If that's all you need to know,
you can generalize the function
foo :: Integer -> Integer -> Integer
foo a b = a*a + b*b
to the following:
foo :: Integral i => i -> i -> i
foo a b = a*a + b*b
Now 'foo' is defined for every type, which is an instance of the class
Integral. Being an instance of that class precisely means that (+), (*)
and some other functions are defined for the particular type. Since
this is all you need to know for 'foo', there is no reason to restrict
it to Integer.
This can be applied to your example, but not verbatim. As said, the two
types String and [String] have little in common. If you want to write a
function with a polymorphic type, you always need to think in terms of
things you know about the types.
The types 'Maybe a' and '[a]' have a common property: [] and Maybe are
both functors. Informally that means that they are types, which
implement some notion of 'mapping a function over the value(s)'.
Technically it means that the 'fmap' function is defined for both:
fmap :: Functor f => (a -> b) -> f a -> f b
Here is your original function:
quote :: [String] -> [String]
quote = map (\s -> "\"" ++ s ++ "\"")
Since the 'map' function is actually just a special case of 'fmap',
which is constrained to lists, knowing that you can generalize 'quote'
to any functor:
quote :: Functor f => f String -> f String
quote = fmap (\s -> "\"" ++ s ++ "\"")
To answer your original question: It is impossible to write a function,
which handles both cases, because the two cases are inherently
incompatible. In other words: Trying to write a Haskell function,
which handles both cases, is pointless by concept.
Greets,
Ertugrul.
Joel Neely <[email protected]> wrote:
> Short version: Is it possible/reasonable to define a single function
> that accepts a single string or a list of strings (in which case it
> maps the single-string "flavor" over the list)?
>
> Longer version: Thus far I know that Haskell allows me to define a
> function on a single string, then define another function that maps
> the first one across a list of strings, as in:
>
> *Main> let quote1 s = "\"" ++ s ++ "\""
>
> *Main> "Quux said " ++ quote1 "foo" ++ " loudly"
> "Quux said \"foo\" loudly"
>
> *Main> let quote = map quote1
>
> *Main> quote ["foo", "baz", "bletch"]
> ["\"foo\"","\"baz\"","\"bletch\""]
>
> (BTW, is it standard terminology to say that quote lifts quote1 to lists?)
>
> In the above I have different names for the two functions. OO
> languages such as Java allow me to overload quote to accept either
> String or List<String> (and return the same type). AFAICT, Haskell's
> parametric polymorphism allows me to define functions (e.g. length)
> which deal with "listness" concepts indifferent to the type contained
> by the list.
>
> Am I missing something, or should I admit to OO wrongheadedness and
> accept that my inability to write a single declaration unifying:
>
> quote :: String -> String
> quote :: [String] -> [String]
>
> is an emphatic clue that I should change my expectations?
>
> Thanks in advance for any enlightenment shed my way!
>
> -jn-
>
--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://blog.ertes.de/
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 11, Issue 3
****************************************