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.  IO String inside a CmdArgs data (Kamil Stachowski)
   2. Re:  IO String inside a CmdArgs data (Daniel Fischer)
   3. Re:  IO String inside a CmdArgs data (Kamil Stachowski)
   4. Re:  IO String inside a CmdArgs data (Brent Yorgey)
   5. Re:  IO String inside a CmdArgs data (Kamil Stachowski)
   6. Re:  IO String inside a CmdArgs data (Brent Yorgey)
   7. Re:  IO String inside a CmdArgs data (Kamil Stachowski)


----------------------------------------------------------------------

Message: 1
Date: Fri, 14 Jan 2011 19:18:58 +0100
From: Kamil Stachowski <[email protected]>
Subject: [Haskell-beginners] IO String inside a CmdArgs data
To: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="utf-8"

Hello,

I am trying to use N. Mitchell's CmdArgs and I would like one of the fields
to store the current time. A minimal example below:


{-# LANGUAGE DeriveDataTypeable #-}

import System.Console.CmdArgs
import System.Time


data FuzzyTimeConf = FuzzyTimeConf { time :: String } deriving (Show, Data,
Typeable)

ftConf = FuzzyTimeConf { time = confDefaultTime }

confDefaultTime = "it is here that I would like to get the current time"

main :: IO ()
main = do
 print =<< cmdArgs ftConf


I want confDefaultTime to store the current time as HH:MM, so I guess I will
also need to extract it in some way.

I've tried many different versions and can't come up with anything working.
confDefaultTime can't be an IO String because than it can't derive Show and
Data which is required for cmdArgs to work in FuzzyTimeConf. However, I
don't seem to be able to find a way to make it a String and hold the actual
current time.

Can you help me, please?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110114/7970ffcd/attachment-0001.htm>

------------------------------

Message: 2
Date: Fri, 14 Jan 2011 19:41:07 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] IO String inside a CmdArgs data
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain;  charset="utf-8"

On Friday 14 January 2011 19:18:58, Kamil Stachowski wrote:
> Hello,
>
> I am trying to use N. Mitchell's CmdArgs and I would like one of the
> fields to store the current time. A minimal example below:
>
>
> {-# LANGUAGE DeriveDataTypeable #-}
>
> import System.Console.CmdArgs
> import System.Time
>
>
> data FuzzyTimeConf = FuzzyTimeConf { time :: String } deriving (Show,
> Data, Typeable)
>
> ftConf = FuzzyTimeConf { time = confDefaultTime }
>
> confDefaultTime = "it is here that I would like to get the current time"
>
> main :: IO ()
> main = do
>  print =<< cmdArgs ftConf
>
>
> I want confDefaultTime to store the current time as HH:MM, so I guess I
> will also need to extract it in some way.
>
> I've tried many different versions and can't come up with anything
> working. confDefaultTime can't be an IO String because than it can't
> derive Show and Data which is required for cmdArgs to work in
> FuzzyTimeConf. However, I don't seem to be able to find a way to make it
> a String and hold the actual current time.
>
> Can you help me, please?

Two things spring to mind:
a) don't use a top-level ftConf, get it inside IO in main:

getFTConf :: IO FuzzyTimeConf
getFTConf = do
  now <- getClockTime -- or whichever time you need
  return $ FuzzyTimeConf { time = convert now }

main = do
  ftConf <- getFTConf
  print =<< cmdArgs ftConf

b) if you absolutely have to have ftConf as a top-level name and it is safe 
here:

import System.IO.Unsafe (unsafePerformIO)

{-# NOINLINE ftConf #-}
ftConf :: FuzzyTimeConf
ftConf = unsafePerformIO $ do
  now <- getClockTime
  return $ FuzzyTimeConf { time = convert now }

a) is preferable if it's possible to do thus.

Cheers,
Daniel



------------------------------

Message: 3
Date: Fri, 14 Jan 2011 19:49:30 +0100
From: Kamil Stachowski <[email protected]>
Subject: Re: [Haskell-beginners] IO String inside a CmdArgs data
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="utf-8"

Wow, that was a quick answer! And it does just what I want. Thanks a lot!

Now, I'll just have to sit down and try to understand it :)

Thanks again,
Kamil Stachowski


On 14 January 2011 19:41, Daniel Fischer
<[email protected]>wrote:

> On Friday 14 January 2011 19:18:58, Kamil Stachowski wrote:
> > Hello,
> >
> > I am trying to use N. Mitchell's CmdArgs and I would like one of the
> > fields to store the current time. A minimal example below:
> >
> >
> > {-# LANGUAGE DeriveDataTypeable #-}
> >
> > import System.Console.CmdArgs
> > import System.Time
> >
> >
> > data FuzzyTimeConf = FuzzyTimeConf { time :: String } deriving (Show,
> > Data, Typeable)
> >
> > ftConf = FuzzyTimeConf { time = confDefaultTime }
> >
> > confDefaultTime = "it is here that I would like to get the current time"
> >
> > main :: IO ()
> > main = do
> >  print =<< cmdArgs ftConf
> >
> >
> > I want confDefaultTime to store the current time as HH:MM, so I guess I
> > will also need to extract it in some way.
> >
> > I've tried many different versions and can't come up with anything
> > working. confDefaultTime can't be an IO String because than it can't
> > derive Show and Data which is required for cmdArgs to work in
> > FuzzyTimeConf. However, I don't seem to be able to find a way to make it
> > a String and hold the actual current time.
> >
> > Can you help me, please?
>
> Two things spring to mind:
> a) don't use a top-level ftConf, get it inside IO in main:
>
> getFTConf :: IO FuzzyTimeConf
> getFTConf = do
>  now <- getClockTime -- or whichever time you need
>  return $ FuzzyTimeConf { time = convert now }
>
> main = do
>  ftConf <- getFTConf
>  print =<< cmdArgs ftConf
>
> b) if you absolutely have to have ftConf as a top-level name and it is safe
> here:
>
> import System.IO.Unsafe (unsafePerformIO)
>
> {-# NOINLINE ftConf #-}
> ftConf :: FuzzyTimeConf
> ftConf = unsafePerformIO $ do
>  now <- getClockTime
>  return $ FuzzyTimeConf { time = convert now }
>
> a) is preferable if it's possible to do thus.
>
> Cheers,
> Daniel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110114/d557accb/attachment-0001.htm>

------------------------------

Message: 4
Date: Fri, 14 Jan 2011 14:00:51 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] IO String inside a CmdArgs data
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Fri, Jan 14, 2011 at 07:41:07PM +0100, Daniel Fischer wrote:
> 
> b) if you absolutely have to have ftConf as a top-level name and it is safe 
> here:
> 
> import System.IO.Unsafe (unsafePerformIO)
> 
> {-# NOINLINE ftConf #-}
> ftConf :: FuzzyTimeConf
> ftConf = unsafePerformIO $ do
>   now <- getClockTime
>   return $ FuzzyTimeConf { time = convert now }

There's already a Hackage package to accomplish this:

  http://hackage.haskell.org/package/acme-now

=)

-Brent



------------------------------

Message: 5
Date: Fri, 14 Jan 2011 20:14:38 +0100
From: Kamil Stachowski <[email protected]>
Subject: Re: [Haskell-beginners] IO String inside a CmdArgs data
To: Brent Yorgey <[email protected]>,      Daniel Fischer
        <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="utf-8"

@Daniel Fischer
Thanks for the offer, it's very kind of you, but I'm afraid I'll just need
to try to understand monads for the hundredth time :/

@Brent Yorgey
Ah, thank you! But that would be the unsafe way, right? I think I should try
to do it the "right" way, but I'm sure this'll come in handy when I get
lost.


On 14 January 2011 20:00, Brent Yorgey <[email protected]> wrote:

> On Fri, Jan 14, 2011 at 07:41:07PM +0100, Daniel Fischer wrote:
> >
> > b) if you absolutely have to have ftConf as a top-level name and it is
> safe
> > here:
> >
> > import System.IO.Unsafe (unsafePerformIO)
> >
> > {-# NOINLINE ftConf #-}
> > ftConf :: FuzzyTimeConf
> > ftConf = unsafePerformIO $ do
> >   now <- getClockTime
> >   return $ FuzzyTimeConf { time = convert now }
>
> There's already a Hackage package to accomplish this:
>
>  http://hackage.haskell.org/package/acme-now
>
> =)
>
> -Brent
>
> _______________________________________________
> 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/20110114/5661be4c/attachment-0001.htm>

------------------------------

Message: 6
Date: Fri, 14 Jan 2011 15:36:28 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] IO String inside a CmdArgs data
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Fri, Jan 14, 2011 at 08:14:38PM +0100, Kamil Stachowski wrote:
> @Daniel Fischer
> Thanks for the offer, it's very kind of you, but I'm afraid I'll just need
> to try to understand monads for the hundredth time :/
> 
> @Brent Yorgey
> Ah, thank you! But that would be the unsafe way, right? I think I should try
> to do it the "right" way, but I'm sure this'll come in handy when I get
> lost.

Yes, I was mostly linking to that package just because it is funny,
it's probably not what you really want to do. =)

-Brent

> 
> 
> On 14 January 2011 20:00, Brent Yorgey <[email protected]> wrote:
> 
> > On Fri, Jan 14, 2011 at 07:41:07PM +0100, Daniel Fischer wrote:
> > >
> > > b) if you absolutely have to have ftConf as a top-level name and it is
> > safe
> > > here:
> > >
> > > import System.IO.Unsafe (unsafePerformIO)
> > >
> > > {-# NOINLINE ftConf #-}
> > > ftConf :: FuzzyTimeConf
> > > ftConf = unsafePerformIO $ do
> > >   now <- getClockTime
> > >   return $ FuzzyTimeConf { time = convert now }
> >
> > There's already a Hackage package to accomplish this:
> >
> >  http://hackage.haskell.org/package/acme-now
> >
> > =)
> >
> > -Brent
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
> >



------------------------------

Message: 7
Date: Fri, 14 Jan 2011 21:45:49 +0100
From: Kamil Stachowski <[email protected]>
Subject: Re: [Haskell-beginners] IO String inside a CmdArgs data
To: Brent Yorgey <[email protected]>
Cc: [email protected]
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="utf-8"

It is funny, indeed :)

In fact, I am after all going to get unsafe because what Daniel Fischer
wrote above worked perfectly until I wanted to add annotations to ftConf
(the "&= summary" bit in http://community.haskell.org/~ndm/cmdargs/). The
only way I can go around the errors I get is precisely unsafe, so ah, you
only live once ;)


On 14 January 2011 21:36, Brent Yorgey <[email protected]> wrote:

> On Fri, Jan 14, 2011 at 08:14:38PM +0100, Kamil Stachowski wrote:
> > @Daniel Fischer
> > Thanks for the offer, it's very kind of you, but I'm afraid I'll just
> need
> > to try to understand monads for the hundredth time :/
> >
> > @Brent Yorgey
> > Ah, thank you! But that would be the unsafe way, right? I think I should
> try
> > to do it the "right" way, but I'm sure this'll come in handy when I get
> > lost.
>
> Yes, I was mostly linking to that package just because it is funny,
> it's probably not what you really want to do. =)
>
> -Brent
>
> >
> >
> > On 14 January 2011 20:00, Brent Yorgey <[email protected]> wrote:
> >
> > > On Fri, Jan 14, 2011 at 07:41:07PM +0100, Daniel Fischer wrote:
> > > >
> > > > b) if you absolutely have to have ftConf as a top-level name and it
> is
> > > safe
> > > > here:
> > > >
> > > > import System.IO.Unsafe (unsafePerformIO)
> > > >
> > > > {-# NOINLINE ftConf #-}
> > > > ftConf :: FuzzyTimeConf
> > > > ftConf = unsafePerformIO $ do
> > > >   now <- getClockTime
> > > >   return $ FuzzyTimeConf { time = convert now }
> > >
> > > There's already a Hackage package to accomplish this:
> > >
> > >  http://hackage.haskell.org/package/acme-now
> > >
> > > =)
> > >
> > > -Brent
> > >
> > > _______________________________________________
> > > Beginners mailing list
> > > [email protected]
> > > http://www.haskell.org/mailman/listinfo/beginners
> > >
>
> _______________________________________________
> 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/20110114/ecaeba02/attachment.htm>

------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 31, Issue 13
*****************************************

Reply via email to