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. type of zipWithPlus (Russ Abbott)
2. Heterogenous list implemented with GADT (Ken Overton)
3. Re: type of zipWithPlus (Daniel Fischer)
4. Re: Heterogenous list implemented with GADT (Daniel Fischer)
5. Re: Heterogenous list implemented with GADT (Ken Overton)
6. Applicative Composition (edgar klerks)
7. Re: Applicative Composition (Brent Yorgey)
8. Re: type of zipWithPlus (Russ Abbott)
----------------------------------------------------------------------
Message: 1
Date: Thu, 30 Sep 2010 11:59:28 -0700
From: Russ Abbott <[email protected]>
Subject: [Haskell-beginners] type of zipWithPlus
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
When I define zipWithPlus at the top level of GHCi, the type is as shown.
> let zipWithPlus = zipWith (+)
zipWithPlus :: [Integer] -> [Integer] -> [Integer]
Why isn't it: (Num a) => a -> a-> a
I was unable to find a way to get the type to be more general. I tried
various declarations within the let using (Num a) => a -> a-> a but none of
them were accepted.
Thanks.
-- Russ Abbott
______________________________________
Professor, Computer Science
California State University, Los Angeles
Google voice: 424-242-USA0 (last character is zero)
blog: http://russabbott.blogspot.com/
vita: http://sites.google.com/site/russabbott/
______________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100930/ff1392c1/attachment-0001.html
------------------------------
Message: 2
Date: Thu, 30 Sep 2010 15:08:01 -0400
From: Ken Overton <[email protected]>
Subject: [Haskell-beginners] Heterogenous list implemented with GADT
To: "[email protected]" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
Hello fellow beginners (and the rest of you, too), I was reading
http://en.wikibooks.org/wiki/Haskell/GADT and I really liked the simple eval
example. But I reached the end and was confused by the following definition of
a heterogenous list:
data TG2 where
MkTG2 :: Show b => [b] -> TG2
I had thought a heterogeneous list was something like
[ 5 , 'Z', 3.14, False ]
How can the TG2 definition support the list I've given above? Or am I just
wrong about what a heterogeneous list is?
Thanks,
-- kov
This email and any attachments may contain information which is confidential
and/or privileged. The information is intended exclusively for the addressee
and the views expressed may not be official policy, but the personal views of
the originator. If you are not the intended recipient, be aware that any
disclosure, copying, distribution or use of the contents is prohibited. If you
have received this email and any file transmitted with it in error, please
notify the sender by telephone or return email immediately and delete the
material from your computer. Internet communications are not secure and Lab49
is not responsible for their abuse by third parties, nor for any alteration or
corruption in transmission, nor for any damage or loss caused by any virus or
other defect. Lab49 accepts no liability or responsibility arising out of or in
any way connected to this email.
------------------------------
Message: 3
Date: Thu, 30 Sep 2010 21:48:30 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] type of zipWithPlus
To: [email protected], [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
On Thursday 30 September 2010 20:59:28, Russ Abbott wrote:
> When I define zipWithPlus at the top level of GHCi, the type is as
> shown.
>
> > let zipWithPlus = zipWith (+)
>
> zipWithPlus :: [Integer] -> [Integer] -> [Integer]
>
> Why isn't it: (Num a) => a -> a-> a
It's the monomorphism restriction. If you bind a name without function
arguments at the prompt (or at the top-level of a module if the name is
exported) and without a type signature, it is given a monomorphic type.
Type inference yields the polymorphic type, then it is monomorphised
according to the defaulting rules. The default for Num constraints is
Integer, hence you get zipWithPlus :: [Integer] -> [Integer] -> [Integer]
>
> I was unable to find a way to get the type to be more general.
Three ways.
1. bind it with a type signature
ghci> let zipWithPlus :: Num a => [a] -> [a] -> [a]; zipWithPlus = zipWith
(+)
ought to work (if it doesn't submit a bug report)
2. bind it with arguments
ghci> let zipWithPlus xs ys = zipWith (+) xs ys
and
ghci> let zipWithPlus xs = zipWith (+) xs
both ought to work (if not, bug report)
3. disable the monomorphism restriction
$ ghci -XNoMonomorphismRestriction
or
ghci> :set -XNoMonomorphismRestriction
disable the MR and give you the polymorphic type without type signatures or
arguments
It's probably a good idea to put
:set -XNoMonomorphismRestriction
into your ~/.ghci
> I tried various declarations within the let using
> (Num a) => a -> a-> a
> but none of them were accepted.
>
> Thanks.
> -- Russ Abbott
------------------------------
Message: 4
Date: Thu, 30 Sep 2010 22:00:13 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Heterogenous list implemented with
GADT
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On Thursday 30 September 2010 21:08:01, Ken Overton wrote:
> Hello fellow beginners (and the rest of you, too), I was reading
> http://en.wikibooks.org/wiki/Haskell/GADT and I really liked the simple
> eval example. But I reached the end and was confused by the following
> definition of a heterogenous list:
>
> data TG2 where
> MkTG2 :: Show b => [b] -> TG2
>
> I had thought a heterogeneous list was something like
>
> [ 5 , 'Z', 3.14, False ]
>
> How can the TG2 definition support the list I've given above?
It can't.
> Or am I just wrong about what a heterogeneous list is?
I rather think the wikibook author expressed (her|him)self incorrectly.
What TG2 does is wrap a list of (henceforth) unknown type (as long as the
type has a Show instance, and that Show instance is made available by
pattern matching).
To achieve something like your example, you'd need
data TG3 where
MkTG3 :: Show a => a -> TG3
xs :: [TG3]
xs = [MkTG3 5, MkTG3 'Z', MkTG3 3.14, MkTG3 False]
>
> Thanks,
>
> -- kov
------------------------------
Message: 5
Date: Thu, 30 Sep 2010 16:13:45 -0400
From: Ken Overton <[email protected]>
Subject: Re: [Haskell-beginners] Heterogenous list implemented with
GADT
To: Daniel Fischer <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"
On Sep 30, 2010, at 4:00 PM, Daniel Fischer wrote:
> What TG2 does is wrap a list of (henceforth) unknown type (as long as the
> type has a Show instance, and that Show instance is made available by
> pattern matching).
Thanks, that sheds some light on the usefulness of GADTs in general for me.
> To achieve something like your example, you'd need
>
> data TG3 where
> MkTG3 :: Show a => a -> TG3
>
> xs :: [TG3]
> xs = [MkTG3 5, MkTG3 'Z', MkTG3 3.14, MkTG3 False]
Much clearer, thanks a lot.
--kov
This email and any attachments may contain information which is confidential
and/or privileged. The information is intended exclusively for the addressee
and the views expressed may not be official policy, but the personal views of
the originator. If you are not the intended recipient, be aware that any
disclosure, copying, distribution or use of the contents is prohibited. If you
have received this email and any file transmitted with it in error, please
notify the sender by telephone or return email immediately and delete the
material from your computer. Internet communications are not secure and Lab49
is not responsible for their abuse by third parties, nor for any alteration or
corruption in transmission, nor for any damage or loss caused by any virus or
other defect. Lab49 accepts no liability or responsibility arising out of or in
any way connected to this email.
------------------------------
Message: 6
Date: Fri, 1 Oct 2010 01:47:09 +0200
From: edgar klerks <[email protected]>
Subject: [Haskell-beginners] Applicative Composition
To: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi All,
I was wondering, why there isn't a composition operator for applicative
functors. Of course it is rather trivial to implement, but it is a useful
feature:
{-# LANGUAGE FlexibleInstances, UndecidableInstances #-}
module ApplicativeComposition where
import Control.Applicative
class (Applicative f) => ApplicativeComposition f where
(<.>) :: f (b -> c) -> f (a -> b) -> f (a -> c)
instance (Applicative f) => ApplicativeComposition f where
(<.>) f g = pure (.) <*> f <*> g
Can this be added to later versions of haskell?
Greets,
Edgar
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100930/1aedb874/attachment-0001.html
------------------------------
Message: 7
Date: Thu, 30 Sep 2010 21:41:04 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Applicative Composition
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Fri, Oct 01, 2010 at 01:47:09AM +0200, edgar klerks wrote:
> Hi All,
>
> I was wondering, why there isn't a composition operator for applicative
> functors. Of course it is rather trivial to implement, but it is a useful
> feature:
I think you've answered your own question: it's rather trivial to
implement. If we added every single useful function to the standard
libraries, we'd be up to our necks.
> {-# LANGUAGE FlexibleInstances, UndecidableInstances #-}
> module ApplicativeComposition where
> import Control.Applicative
>
> class (Applicative f) => ApplicativeComposition f where
> (<.>) :: f (b -> c) -> f (a -> b) -> f (a -> c)
>
> instance (Applicative f) => ApplicativeComposition f where
> (<.>) f g = pure (.) <*> f <*> g
>
> Can this be added to later versions of haskell?
You can always make a formal proposal [1], although judging by past
discussions of similar sorts of things I doubt it would be accepted,
for the reasons I wrote above.
Also, why bother making a new ApplicativeComposition type class?
Since you can simply implement (<.>) in terms of existing Applicative
methods the new type class doesn't really add anything.
-Brent
Footnotes:
[1] http://www.haskell.org/haskellwiki/Library_submissions
------------------------------
Message: 8
Date: Thu, 30 Sep 2010 20:43:19 -0700
From: Russ Abbott <[email protected]>
Subject: Re: [Haskell-beginners] type of zipWithPlus
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Thanks. I tried the first two, which worked.
Previously I had tried:
> let (zipWithPlus :: Num a => [a] -> [a] -> [a]) = zipWith (+)
<interactive>:1:5:
Illegal signature in pattern: (Num a) => [a] -> [a] -> [a]
Use -XScopedTypeVariables to permit it
I tried setting -XScopedTypeVariables. When I ran it again I got a different
error message:
Prelude> let (zipWithPlus :: Num a => [a] -> [a] -> [a]) = zipWith (+)
<interactive>:1:5:
Illegal polymorphic or qualified type:
forall a. (Num a) => [a] -> [a] -> [a]
Perhaps you intended to use -XRankNTypes or -XRank2Types
In a pattern type signature: (Num a) => [a] -> [a] -> [a]
In the pattern: zipWithPlus :: (Num a) => [a] -> [a] -> [a]
In a pattern binding:
(zipWithPlus :: (Num a) => [a] -> [a] -> [a]) = zipWith (+)
-- Russ Abbott
______________________________________
Professor, Computer Science
California State University, Los Angeles
Google voice: 424-242-USA0 (last character is zero)
blog: http://russabbott.blogspot.com/
vita: http://sites.google.com/site/russabbott/
______________________________________
On Thu, Sep 30, 2010 at 12:48 PM, Daniel Fischer
<[email protected]>wrote:
> let zipWithPlus xs ys = zipWith (+) xs ys
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100930/4d0cba39/attachment.html
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 27, Issue 64
*****************************************