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.  haskell Time (Claudia Weber)
   2. Re:  haskell Time (Brent Yorgey)
   3. Re:  haskell Time (Corentin Dupont)


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

Message: 1
Date: Mon, 01 Dec 2014 16:21:49 +0100
From: Claudia Weber <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] haskell Time
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

Hi guys,?
?
I'm ?new to Haskell and I'm just trying out some easy functions right now, but 
I'm having some trouble here...
?
I want to display a clock
?
type Time = (Int, Int)
?
(hoursx,minutesy) x ={0,1,...,23} y={0,1,...,59} where I can add hours and 
minutes or set back time.?
If its 23,58 for example and I want to add 35 minutes, the clock has to set to 
0,33 not 24,23.
?
Because I'm just getting started with Haskell, I have nooo idea what to do.
Would be great if someone could help me out with this :)
?


---
Alle Postf?cher an einem Ort. Jetzt wechseln und E-Mail-Adresse mitnehmen! 
Rundum gl?cklich mit freenetMail
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20141201/b581e832/attachment-0001.html>

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

Message: 2
Date: Mon, 1 Dec 2014 11:16:17 -0500
From: Brent Yorgey <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] haskell Time
Message-ID:
        <CAH0njdvXgkj=pi3kn-m7ho0_tcnccamwiyphjx4qnyf+bk_...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi Claudia,

It sounds like you will find the mod and div functions helpful.  div does
integer division, that is, it rounds down to the nearest integer.  mod
gives the remainder after doing division.

For example:

  (58 + 33) `div` 60 = 1
  (58 + 33) `mod` 60 = 33

-Brent

On Mon, Dec 1, 2014 at 10:21 AM, Claudia Weber <[email protected]>
wrote:

> Hi guys,
>
>
>
> I'm  new to Haskell and I'm just trying out some easy functions right now,
> but I'm having some trouble here..
>
>
>
> I want to display a clock
>
>
>
> type Time = (Int, Int)
>
>
>
> (hoursx,minutesy) x ={0,1,...,23} y={0,1,...,59} where I can add hours and
> minutes or set back time.
>
> If its 23,58 for example and I want to add 35 minutes, the clock has to
> set to 0,33 not 24,23.
>
>
>
> Because I'm just getting started with Haskell, I have nooo idea what to do.
>
> Would be great if someone could help me out with this :)
>
>
>
>
> ---
> Alle Postf?cher an einem Ort Jetzt wechseln und E-Mail-Adresse mitnehmen! 
> Rundum
> gl?cklich mit freenetMail <http://email.freenet.de/basic/Informationen>
>
> _______________________________________________
> 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/20141201/330cf4b6/attachment-0001.html>

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

Message: 3
Date: Mon, 1 Dec 2014 19:16:50 +0100
From: Corentin Dupont <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] haskell Time
Message-ID:
        <caeyhvmrr0-brirrfddoy53q-ondb2vtmhh6ag6k7orry9zp...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi Claudia,
your type "Time" is good.
Here is how you'd define the functions for adding hours:

addHour :: Int -> Time -> Time
addHour myHour (hour, minute) = ((hour + myHour) `mod` 24, minute)

As can be seen in the first line, this function takes an integer where you
put the number of hours to add, takes a certain Time and then returns an
updated time.
You can try that in GHCi: put the code in a file and load it in GHCi (you
need to install Haskell platform: https://www.haskell.org/platform/).

$ ghci my_file.hs

Then you can play with your function by typing:

$ addHour 5 (10, 0)
(15, 0)

If you want a real program, you need to add some I/O:

import Data.Time

main = do
   time <- getCurrentTime
   putStrLn (show time)

You can compile this short program with:
ghc my_file.hs

Launch it with (or click on the generated executable under windows):
$ ./my_file
2014-12-01 18:12:26.989883 UTC

Tada! You have a clock.

Good luck with Haskell, it's not always easy but very rewarding language.

Corentin



On Mon, Dec 1, 2014 at 4:21 PM, Claudia Weber <[email protected]>
wrote:

> Hi guys,
>
>
>
> I'm  new to Haskell and I'm just trying out some easy functions right now,
> but I'm having some trouble here..
>
>
>
> I want to display a clock
>
>
>
> type Time = (Int, Int)
>
>
>
> (hoursx,minutesy) x ={0,1,...,23} y={0,1,...,59} where I can add hours and
> minutes or set back time.
>
> If its 23,58 for example and I want to add 35 minutes, the clock has to
> set to 0,33 not 24,23.
>
>
>
> Because I'm just getting started with Haskell, I have nooo idea what to do.
>
> Would be great if someone could help me out with this :)
>
>
>
>
> ---
> Alle Postf?cher an einem Ort Jetzt wechseln und E-Mail-Adresse mitnehmen! 
> Rundum
> gl?cklich mit freenetMail <http://email.freenet.de/basic/Informationen>
>
> _______________________________________________
> 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/20141201/ffabad81/attachment-0001.html>

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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 78, Issue 1
****************************************

Reply via email to