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: Signatures (Daniel Fischer)
2. get date (Luca Ciciriello)
3. Re: get date (Felipe Lessa)
4. State monad question (Jordan Cooper)
5. Re: State monad question (Drew Haven)
6. Re: State monad question (Jordan Cooper)
7. Re: State monad question (Daniel Fischer)
8. Re: State monad question (Jordan Cooper)
9. searching for a file (Michael Mossey)
10. Re: howto reason infinite lists (prad)
----------------------------------------------------------------------
Message: 1
Date: Wed, 23 Jun 2010 19:14:54 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Signatures
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On Wednesday 23 June 2010 19:01:21, Colin Paul Adams wrote:
> >>>>> "Patrick" == Patrick LeBoutillier <[email protected]>
writes:
> >>> So
> >>>
> >>> nightmare :: Offspring ?
>
> If you make
>
> Patrick> sex :: Partner -> IO [STD]
>
> Patrick> then perhaps
>
> Patrick> nightmare :: [STD]
>
> Patrick> becomes more universal...
>
>
>
> What's an STD?
Sexually transmitted disease
------------------------------
Message: 2
Date: Wed, 23 Jun 2010 20:03:16 +0200
From: Luca Ciciriello <[email protected]>
Subject: [Haskell-beginners] get date
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
How can I get the current system date-time in Haskell?
I've used the library Time, but on MacOS X 10.6.4 the year is always 0.
Luca.
------------------------------
Message: 3
Date: Wed, 23 Jun 2010 15:13:44 -0300
From: Felipe Lessa <[email protected]>
Subject: Re: [Haskell-beginners] get date
To: Luca Ciciriello <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Wed, Jun 23, 2010 at 08:03:16PM +0200, Luca Ciciriello wrote:
> How can I get the current system date-time in Haskell?
>
> I've used the library Time, but on MacOS X 10.6.4 the year is always 0.
>
> Luca.
Do you mean, you used getCurrentTime from the time package[1]?
What does the following line do?
(toGregorian . utctDay) `fmap` getCurrentTime
On my system,
GHCi, version 6.10.4: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Prelude> :m Data.Time
Prelude Data.Time> (toGregorian . utctDay) `fmap` getCurrentTime
Loading package old-locale-1.0.0.1 ... linking ... done.
Loading package time-1.1.4 ... linking ... done.
(2010,6,23)
http://hackage.haskell.org/packages/archive/time/1.2.0.3/doc/html/Data-Time-Clock.html#v%3AgetCurrentTime
HTH,
--
Felipe.
------------------------------
Message: 4
Date: Wed, 23 Jun 2010 14:10:00 -0700
From: Jordan Cooper <[email protected]>
Subject: [Haskell-beginners] State monad question
To: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
I have two pieces of state I'm managing:
type FooState = State Foo Foo
type BarState = State Bar Bar
There is a bit of interplay between them, and I want a function that
does something like:
importantFunction :: Foo -> Bar -> (Foo, Bar)
The problem is, >>= only works when I'm chaining all of the same type
of state. So I can't do:
modifiesFoo >>= \foo ->
modifiesBar foo >>= \bar ->
return (foo, bar)
So how do I get the results of both modifications back? I hope that
makes sense. Programming in Haskell is proving to be very difficult; I
once again fear I'm too stupid.
------------------------------
Message: 5
Date: Wed, 23 Jun 2010 14:32:10 -0700
From: Drew Haven <[email protected]>
Subject: Re: [Haskell-beginners] State monad question
To: Jordan Cooper <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
I doubt it's an issue of being too stupid. If you come from more
traditional languages, then Haskell requires that to rewire your brain
to think in Haskell. It's very different. It appears hard because
there is a lot of work to re-learning things you thought you knew.
As for combining two state monads, is there a reason you cannot
combine them into one large state?
It looks what you are doing is:
importantFunction initialFoo initialBar =
let foo = execState modifiesFoo initialFoo
in (foo, execState (modifiesBar foo) initialBar)
Which would have the type signature you are expecting and wouldn't
need to be monadic.
Drew Haven
[email protected]
On Wed, Jun 23, 2010 at 2:10 PM, Jordan Cooper <[email protected]> wrote:
> I have two pieces of state I'm managing:
> type FooState = State Foo Foo
> type BarState = State Bar Bar
>
> There is a bit of interplay between them, and I want a function that
> does something like:
> importantFunction :: Foo -> Bar -> (Foo, Bar)
>
> The problem is, >>= only works when I'm chaining all of the same type
> of state. So I can't do:
> modifiesFoo >>= \foo ->
> modifiesBar foo >>= \bar ->
> return (foo, bar)
>
> So how do I get the results of both modifications back? I hope that
> makes sense. Programming in Haskell is proving to be very difficult; I
> once again fear I'm too stupid.
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 6
Date: Wed, 23 Jun 2010 14:48:42 -0700
From: Jordan Cooper <[email protected]>
Subject: Re: [Haskell-beginners] State monad question
To: Drew Haven <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
On 6/23/10, Drew Haven <[email protected]> wrote:
> I doubt it's an issue of being too stupid. If you come from more
> traditional languages, then Haskell requires that to rewire your brain
> to think in Haskell. It's very different. It appears hard because
> there is a lot of work to re-learning things you thought you knew.
You're probably right, but I can't help but have some doubts :)
> As for combining two state monads, is there a reason you cannot
> combine them into one large state?
>
> It looks what you are doing is:
>
> importantFunction initialFoo initialBar =
> let foo = execState modifiesFoo initialFoo
> in (foo, execState (modifiesBar foo) initialBar)
>
> Which would have the type signature you are expecting and wouldn't
> need to be monadic.
Well, two things that I guess are important to mention:
In my program, it's not Foo and Bar, but Cards and Players. Any player
can potentially act on any card, even if it's not their own, thus I
felt they probably shouldn't be part of the same state (though perhaps
I am wrong in this).
Secondly, as to why I wanted to use a monad here, importantFunction
(which is called playerTurn in the real program) would contain a
series of functions that would modify Cards and Players, not just one
each as in my initial example. Thus it seems like I'd have to end up
with let foo... let foo'... etc. which, from my reading in RWH, seems
to be an acceptable use for a State monad.
Thanks for your answer, and to Matthew for the encouragement :)
------------------------------
Message: 7
Date: Thu, 24 Jun 2010 00:11:52 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] State monad question
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On Wednesday 23 June 2010 23:48:42, Jordan Cooper wrote:
>
> Well, two things that I guess are important to mention:
>
> In my program, it's not Foo and Bar, but Cards and Players. Any player
> can potentially act on any card, even if it's not their own, thus I
> felt they probably shouldn't be part of the same state (though perhaps
> I am wrong in this).
>
> Secondly, as to why I wanted to use a monad here, importantFunction
> (which is called playerTurn in the real program) would contain a
> series of functions that would modify Cards and Players, not just one
> each as in my initial example. Thus it seems like I'd have to end up
> with let foo... let foo'... etc. which, from my reading in RWH, seems
> to be an acceptable use for a State monad.
>
> Thanks for your answer, and to Matthew for the encouragement :)
Maybe a Monad transformer would be helpful, something along the lines of
StateT Player (State Card) foo
then you can work in the inner Monad (State Card) via lift.
fooBar = do
cardResult <- lift cardAction
playerResult <- playerAction cardResult
return (cardResult, playerResult)
------------------------------
Message: 8
Date: Wed, 23 Jun 2010 16:10:42 -0700
From: Jordan Cooper <[email protected]>
Subject: Re: [Haskell-beginners] State monad question
To: Daniel Fischer <[email protected]>
Cc: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Alright, I'll give this a shot. I've never used monad transformers
before, so it should be interesting :)
On 6/23/10, Daniel Fischer <[email protected]> wrote:
> On Wednesday 23 June 2010 23:48:42, Jordan Cooper wrote:
>>
>> Well, two things that I guess are important to mention:
>>
>> In my program, it's not Foo and Bar, but Cards and Players. Any player
>> can potentially act on any card, even if it's not their own, thus I
>> felt they probably shouldn't be part of the same state (though perhaps
>> I am wrong in this).
>>
>> Secondly, as to why I wanted to use a monad here, importantFunction
>> (which is called playerTurn in the real program) would contain a
>> series of functions that would modify Cards and Players, not just one
>> each as in my initial example. Thus it seems like I'd have to end up
>> with let foo... let foo'... etc. which, from my reading in RWH, seems
>> to be an acceptable use for a State monad.
>>
>> Thanks for your answer, and to Matthew for the encouragement :)
>
> Maybe a Monad transformer would be helpful, something along the lines of
>
> StateT Player (State Card) foo
>
> then you can work in the inner Monad (State Card) via lift.
>
> fooBar = do
> cardResult <- lift cardAction
> playerResult <- playerAction cardResult
> return (cardResult, playerResult)
>
------------------------------
Message: 9
Date: Wed, 23 Jun 2010 20:56:38 -0700
From: Michael Mossey <[email protected]>
Subject: [Haskell-beginners] searching for a file
To: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Can I get a hint how to do this:
Given a directory D and a file extension E, find the newest file in D
among all files with extension E.
I wouldn't mind if you point me to the functions that are useful and
leave the rest as an exercise. Or even just point me to the module(s)
that is(are) useful.
Thanks,
Mike
------------------------------
Message: 10
Date: Wed, 23 Jun 2010 20:59:04 -0700
From: prad <[email protected]>
Subject: [Haskell-beginners] Re: howto reason infinite lists
To: [email protected]
Message-ID: <20100623205904.6a911...@gom>
Content-Type: text/plain; charset=UTF-8
On Wed, 23 Jun 2010 13:02:38 +0200
Heinrich Apfelmus <[email protected]> wrote:
> The answer to that is that any recursively defined value is
> obtained from a sequence of approximations.
>
that is a wonderful and detailed explanation. i didn't ever understand
what bottom was. thx for the wikibooks link as well.
> The key message to take away is that you also need some way (â¥) to
> express recursive definitions that might loop forever.
>
yes i understand this now.
my a,b,c was put there because i just assumed nothing would be
evaluated till required so the idea of a terminating condition didn't
really seem necessary especially on an infinite list, but i'm getting a
feel for how you worked it in with the concept of an approximation
which is certainly something i had never thought of in that way.
thank you very much for helping alter my reasoning process and that
looks like a great site you have:
http://apfelmus.nfshost.com/
i'll be dropping by!
--
In friendship,
prad
... with you on your journey
Towards Freedom
http://www.towardsfreedom.com (website)
Information, Inspiration, Imagination - truly a site for soaring I's
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 24, Issue 31
*****************************************