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: Making sense of currying in the context of the Hask
Category (Brent Yorgey)
2. Re: firering event in netwire (Nathan H?sken)
3. Re: firering event in netwire (Ertugrul S?ylemez)
4. Re: firering event in netwire (Ertugrul S?ylemez)
5. Re: Using my first map instance (Darren Grant)
6. Re: Using my first map instance (Daniel Trstenjak)
----------------------------------------------------------------------
Message: 1
Date: Sat, 29 Sep 2012 07:09:56 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Making sense of currying in the
context of the Hask Category
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Fri, Sep 28, 2012 at 08:53:11PM -0400, Lino Rosa wrote:
> Thanks for the responses :) I've read on cartesian closed categories,
> but I guess I need more time for it to sink in - my knowlege on
> category theory is *very* limited.
>
> Still, continuing on the Int + Int example. Would this be the sequence
> of transformations, then?
You seem quite set on this idea of there being "a sequence of
transformations", I am not sure why. When thinking about (+) there
are many different related arrows; some of them form sequences (can be
composed) and some can't. So this is not necessarily a helpful way of
thinking about things.
> Int -> (Int -> Int) -> Int
> (+) (z) (?)
>
> What do I label the arrow (?) ?
That said, you could label the arrow (?) with something like ($2)
which means "apply a function to the argument 2".
> I understand the first transformation as "function (+) when applied to
> an Int will result in (Int -> Int)". How would I describe function (?)
> similarly ?
> It's almost as it the arrow is z and (?) is the Int and I'm applying z
> to (?), but that makes no sense!
>
> If I understood correctly, 'z' would be a special type, one which when
> applied (?) would return the final Int. This comes Hask being
> cartesian closed. Still I'm clueless on the arrow (?)
I think you actually had it right here. Indeed it does not make sense
for (?) to be an Int, but it can indeed be a function like "apply the
input to the argument 2". Having an "apply" operation is one of the
criteria for being cartesian closed.
-Brent
>
> On Fri, Sep 28, 2012 at 8:07 AM, Kim-Ee Yeoh <[email protected]> wrote:
> > Hi Lino,
> >
> > Brent gave an excellent answer. Looking up "cartesian closed category"
> > should yield even more insights.
> >
> > On Fri, Sep 28, 2012 at 9:07 AM, Lino Rosa <[email protected]>
> > wrote:
> >
> >> That's the
> >> function resulting from the previous partial application of (+), but
> >> that fuction only exists at run time, after you apply the first one.
> >
> >
> > When you speak of a function that "only exists at run time", I think you're
> > alluding to partial evaluation. Haskell doesn't do that, although many have
> > wished for it.
> >
> >
> > -- Kim-Ee
> >
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 2
Date: Sat, 29 Sep 2012 19:19:46 +0200
From: Nathan H?sken <[email protected]>
Subject: Re: [Haskell-beginners] firering event in netwire
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On 09/29/2012 08:56 AM, Ertugrul S?ylemez wrote:
>> Or asked differently, how is the "keyDown" event defined, that was
>> talked of in an earlier mail?
>
> In the direct case you can define it as a simple composition:
>
> isSym :: KeySym -> SDL.Event -> Bool
> isSym s (KeyDown s') = s == s'
> isSym _ _ = False
>
> keyDown = require . isSym
>
While I understand the principals, I am unsure about the practical usage.
The input of keyDown is an SDL.Event. But in an application, I would
have a list of Events for every invocation of stepWire. So I could
define keyDown like this:
keyDown s = require . and . map (isSym s)
That would give me an event when my desired keypress event is in the
list of input events.
but if I then want to create a wire passed in this which outputs if a
given key is currently pressed, I would attempt something like this:
isPressed :: KeySym -> WireP [SDL.Event] Bool
isPressed s = hold . (True . (keyDown s) <|> False . (keyUp s))
But if some fast typer releases and presses within one stepWire a
certain key, isPressed would produce an incorrect result.
Regards,
Nathan
------------------------------
Message: 3
Date: Sun, 30 Sep 2012 05:39:20 +0200
From: Ertugrul S?ylemez <[email protected]>
Subject: Re: [Haskell-beginners] firering event in netwire
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Nathan H?sken <[email protected]> wrote:
> >> Or asked differently, how is the "keyDown" event defined, that was
> >> talked of in an earlier mail?
> >
> > In the direct case you can define it as a simple composition:
> >
> > isSym :: KeySym -> SDL.Event -> Bool
> > isSym s (KeyDown s') = s == s'
> > isSym _ _ = False
> >
> > keyDown = require . isSym
> >
>
> While I understand the principals, I am unsure about the practical
> usage. The input of keyDown is an SDL.Event. But in an application, I
> would have a list of Events for every invocation of stepWire. So I
> could define keyDown like this:
>
> keyDown s = require . and . map (isSym s)
>
> That would give me an event when my desired keypress event is in the
> list of input events.
> but if I then want to create a wire passed in this which outputs if a
> given key is currently pressed, I would attempt something like this:
>
> isPressed :: KeySym -> WireP [SDL.Event] Bool
> isPressed s = hold . (True . (keyDown s) <|> False . (keyUp s))
>
> But if some fast typer releases and presses within one stepWire a
> certain key, isPressed would produce an incorrect result.
You can still write isPressed by interpreting it as "has been pressed"
instead:
isPressed :: KeySym -> WireP [SDL.Event] Bool
isPressed sym =
True <$ keyUp sym . keyDown sym <|>
fix (\again ->
False . not (keyDown sym) -->
True . not (keyUp sym) -->
again)
However, I rather recommend against passing multiple SDL events at once.
Wires can handle individual events much better and, when properly
designed, also faster.
Greets,
Ertugrul
--
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120930/c0ae3010/attachment-0001.pgp>
------------------------------
Message: 4
Date: Sun, 30 Sep 2012 05:45:55 +0200
From: Ertugrul S?ylemez <[email protected]>
Subject: Re: [Haskell-beginners] firering event in netwire
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Ertugrul S?ylemez <[email protected]> wrote:
> False . not (keyDown sym) -->
> True . not (keyUp sym) -->
Of course that should be:
False <$ not (keyDown sym) -->
True <$ not (keyUp sym) -->
Greets,
Ertugrul
--
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120930/3d42f465/attachment-0001.pgp>
------------------------------
Message: 5
Date: Sun, 30 Sep 2012 00:01:09 -0700
From: Darren Grant <[email protected]>
Subject: Re: [Haskell-beginners] Using my first map instance
To: Chadda? Fouch? <[email protected]>
Cc: [email protected]
Message-ID:
<ca+jd6shny1wpnbkfj4fbegruhmc5fzwii9zbqrmwujxix6m...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
On Sat, Sep 29, 2012 at 2:36 AM, Chadda? Fouch?
<[email protected]> wrote:
> On Sat, Sep 29, 2012 at 2:44 AM, Darren Grant <[email protected]> wrote:
>> On Fri, Sep 28, 2012 at 4:57 PM, Sean Perry <[email protected]> wrote:
>>>
>>>
>>> Have you looked at
>>> http://www.haskell.org/haskellwiki/Euler_problems/11_to_20#Problem_14?
>>>
>>> The page is full of interesting and fast solutions once you have worked out
>>> your own versions.
>>>
>>
>> Hah I didn't know the Haskell Wiki had a Project Euler page. I'll
>> definitely be reviewing with that resource.
>>
>> I notice the use of Array instead of Map, and the careful use of
>> unboxed types. :)
>>
>
> This comment is misleading, there are no unboxed type in this solution
> (maybe the author meant that this compiled down to unboxed types with
> optimisations but the Haskell code definitely use boxed types : Int
> and Word32) though there's a little bit of parallelism involved (could
> be improved).
You are correct. Thanks for pointing out the distinction between
compiler optimizing down to unboxed types and actually declaring these
types in code.
> The use of a functional (immutable) Array here makes perfect sense
> since the keys are effectively an interval of Int... Note that my old
> Array version rely on the laziness of the Array to make it work, this
> is basically dynamic programming where the order of computation
> appears natural but only because laziness means it will be determined
> by the computation itself. This is perfectly functional, no need to
> resort to any imperative style here (or most everywhere in project
> Euler).
>
> --
> Jeda?
This is exactly the kind of recursive function I was trying to set up
with map, but didn't get the algorithm right. I expect the immutable
Array must be much lighter weight than the immutable Map.
Cheers,
Darren
------------------------------
Message: 6
Date: Sun, 30 Sep 2012 11:11:42 +0200
From: Daniel Trstenjak <[email protected]>
Subject: Re: [Haskell-beginners] Using my first map instance
To: Darren Grant <[email protected]>
Cc: [email protected]
Message-ID:
<capz0sw4tkxjyndim5gtw_nx+sp60gqqnrnbgbqegz7ntufo...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Hi Darren,
Am 30.09.2012 09:02 schrieb "Darren Grant"
> This is exactly the kind of recursive function I was trying to set up
> with map, but didn't get the algorithm right. I expect the immutable
> Array must be much lighter weight than the immutable Map.
using an array as cache is the fastes approach.
I implemented a C++ version using an array (~0.03s) which is orders of
magnitude faster than the map version (~2.5s).
I also tried a Haskell version with an unboxed, mutable Data.Vector using
explict tail recursion, but this version was only 2 times faster than a
lazy Data.Vector version (~0.4s).
I would like to see a Haskell version which is in the same ballpark than
the fastes C++ version, but still quite high level.
Greetings,
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120930/3e660698/attachment-0001.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 51, Issue 45
*****************************************