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. Simpler than lifting (Adrian May)
2. Re: Simpler than lifting (Brandon Allbery)
3. Re: Simpler than lifting (Brent Yorgey)
4. Re: Simpler than lifting (Daniel Trstenjak)
5. Re: Simpler than lifting (Adrian May)
6. newtype with a typclass (R?zvan Rotaru)
7. A good data structure for representing a tic-tac-toe board?
(Costello, Roger L.)
8. Re: newtype with a typclass (Brandon Allbery)
----------------------------------------------------------------------
Message: 1
Date: Mon, 18 Mar 2013 21:59:28 +0800
From: Adrian May <[email protected]>
Subject: [Haskell-beginners] Simpler than lifting
To: [email protected]
Message-ID:
<cad-ubzfbftutgwqh5baodxofvhjiwmqao3khxsin0mr5s95...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi All,
I have this in my code:
infixl 6 ~+, ~-
f ~+ g = \p -> f p + g p
f ~- g = \p -> f p - g p
but I feel that the prelude must have already taken care of such things.
What's the proper way to do it?
Thanks in advance,
Adrian.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130318/849bae5a/attachment-0001.htm>
------------------------------
Message: 2
Date: Mon, 18 Mar 2013 10:15:53 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] Simpler than lifting
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CAKFCL4UYjTz-U3ne1BJPuNQBpF6_BBgj5E5VC6F=-ek0yy5...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Mon, Mar 18, 2013 at 9:59 AM, Adrian May
<[email protected]>wrote:
> infixl 6 ~+, ~-
> f ~+ g = \p -> f p + g p
> f ~- g = \p -> f p - g p
>
> but I feel that the prelude must have already taken care of such things.
> What's the proper way to do it?
>
Not in the Prelude (which is specified by the Haskell Language Report and
difficult to change), but I think you want to look at Control.Applicative.
--
brandon s allbery kf8nh sine nomine associates
[email protected] [email protected]
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130318/0917a8c0/attachment-0001.htm>
------------------------------
Message: 3
Date: Mon, 18 Mar 2013 10:17:44 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Simpler than lifting
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Mon, Mar 18, 2013 at 10:15:53AM -0400, Brandon Allbery wrote:
> On Mon, Mar 18, 2013 at 9:59 AM, Adrian May
> <[email protected]>wrote:
>
> > infixl 6 ~+, ~-
> > f ~+ g = \p -> f p + g p
> > f ~- g = \p -> f p - g p
> >
> > but I feel that the prelude must have already taken care of such things.
> > What's the proper way to do it?
> >
>
> Not in the Prelude (which is specified by the Haskell Language Report and
> difficult to change), but I think you want to look at
> Control.Applicative.
In particular, (~+) = liftA2 (+), and similarly for (~-). This uses
the ((->) e) instance of Applicative.
-Brent
------------------------------
Message: 4
Date: Mon, 18 Mar 2013 16:23:13 +0100
From: Daniel Trstenjak <[email protected]>
Subject: Re: [Haskell-beginners] Simpler than lifting
To: [email protected]
Message-ID: <20130318152313.GA28800@machine>
Content-Type: text/plain; charset=us-ascii
> In particular, (~+) = liftA2 (+), and similarly for (~-). This uses
> the ((->) e) instance of Applicative.
Or by using '<$>' and '<*>', which is a bit more general:
(+) <$> f <*> g
funcWith3Args <$> f <*> g <*> h
Greetings,
Daniel
------------------------------
Message: 5
Date: Mon, 18 Mar 2013 23:27:01 +0800
From: Adrian May <[email protected]>
Subject: Re: [Haskell-beginners] Simpler than lifting
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<cad-ubzhpezn7x68ky6bgxujhzxvujrfsj__6fycft4vokuf...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Thanks everyone! I knew it would be in there somewhere but I wasn't sure
where to look. I'll play with that stuff in the morning.
Adrian.
On 18 March 2013 23:23, Daniel Trstenjak <[email protected]> wrote:
>
> > In particular, (~+) = liftA2 (+), and similarly for (~-). This uses
> > the ((->) e) instance of Applicative.
>
> Or by using '<$>' and '<*>', which is a bit more general:
>
> (+) <$> f <*> g
>
> funcWith3Args <$> f <*> g <*> h
>
>
> Greetings,
> Daniel
>
> _______________________________________________
> 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/20130318/d62ddd59/attachment-0001.htm>
------------------------------
Message: 6
Date: Mon, 18 Mar 2013 17:43:10 +0200
From: R?zvan Rotaru <[email protected]>
Subject: [Haskell-beginners] newtype with a typclass
To: [email protected]
Message-ID:
<cap33cnakgekp_l-emybl0wwn+c6xcmm9jnrcrzkd4m3lf8f...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi,
It seems that type constructors don't allow usage of typeclasses. Is it not
possible to create polymorphic types in Haskell by declaration?
For example I want a map with String keys and anything that is Showable as
values:
newtype MyMap = Map String Show
How can I do that?
Thanks,
Razvan
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130318/e7fbb1e9/attachment-0001.htm>
------------------------------
Message: 7
Date: Mon, 18 Mar 2013 15:54:58 +0000
From: "Costello, Roger L." <[email protected]>
Subject: [Haskell-beginners] A good data structure for representing a
tic-tac-toe board?
To: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="us-ascii"
Hi Folks,
Currently I am representing a tic-tac-toe board as a string, with 'X' denoting
player 1 and 'O' denoting player 2. For example, I represent this 2x2 game
board:
'X' |
-----------------------
| 'O'
with this string: "X O"
The nice thing about that representation is that it is each to identify which
cells are filled or empty, and it is easy to mark a cell with an 'X' or 'O'.
The problem with the representation is that it is difficult to determine when a
player has won.
Can you recommend a representation that makes it easy to:
1. determine when a player has won
2. identify cells that are filled or empty
3. mark an empty cell
/Roger
------------------------------
Message: 8
Date: Mon, 18 Mar 2013 12:34:29 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] newtype with a typclass
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CAKFCL4XDU4=24yHOxk4k-BuS_SNew6Wy_n6g+V4xJ==gn-s...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Mon, Mar 18, 2013 at 11:43 AM, R?zvan Rotaru <[email protected]>wrote:
> It seems that type constructors don't allow usage of typeclasses. Is it
> not possible to create polymorphic types in Haskell by declaration?
>
Not directly, no. It is possible to use existentials to do this ? at the
cost that you lose the ability to do anything but what you have declared
about it. For example, if you were to use this to make a map of Show-able
values, the *only* thing you can do with the value is invoke "show" on it
(in particular: you cannot pull out the value directly, because the only
thing you know about it is that "show" works on it; you otherwise have no
idea what it is!). And with such a value, referential transparency means
there is no difference between this and storing the *result* of invoking
"show" on it (that is, a String) instead, and laziness means that it may
well actually store a thunk that will invoke "show" when the value is
needed instead of computing and storing the value, so that there is in fact
no difference between the two except that the type is much more complicated
and both the type and the code are correspondingly more difficult to
understand.
What problem are you trying to solve by obfuscating things in this manner?
Also note that most times when someone is trying to do this, they have
confused typeclasses with OOP; they are not, and trying to treat them as
such *will* lead you into dead ends.
--
brandon s allbery kf8nh sine nomine associates
[email protected] [email protected]
unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130318/1b46b8b9/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 57, Issue 26
*****************************************