Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  How would you implement Instant and Interval (martin)
   2. Re:  How would you implement Instant and Interval
      (Imants Cekusins)
   3. Re:  How would you implement Instant and Interval (Daniel Bergey)
   4.  New chapter in Learning Haskell: fractal structures
      (Manuel M T Chakravarty)
   5.  lists strange behaviour (galeo...@tiscali.it)
   6. Re:  lists strange behaviour (Kim-Ee Yeoh)


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

Message: 1
Date: Tue, 27 Oct 2015 18:53:59 +0100
From: martin <martin.drautzb...@web.de>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] How would you implement Instant and
        Interval
Message-ID: <562fba37.20...@web.de>
Content-Type: text/plain; charset=utf-8

Hello all

If I define an Instant as a point in Time and an Interval as the difference 
between two Instants, and I also want to use
(+) and (-), how can I do this.

My initial thought making them instances of the Num class, but that does not 
work. (-) is okay on Intervals, but on
Instant it returns a different type (Interval).

Is it possible at all to define a typeclass with (-) :: Instant -> Instant -> 
Interval without using language extensions?


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

Message: 2
Date: Tue, 27 Oct 2015 20:21:57 +0100
From: Imants Cekusins <ima...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] How would you implement Instant and
        Interval
Message-ID:
        <CAP1qinZDSZ-04dawVN=ryfdnye9rydvrczko+zmmvprrba0...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Would this package help:

http://hackage.haskell.org/package/time-interval

?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20151027/7c58e518/attachment-0001.html>

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

Message: 3
Date: Tue, 27 Oct 2015 16:40:29 -0400
From: Daniel Bergey <ber...@alum.mit.edu>
To: martin <martin.drautzb...@web.de>, The Haskell-Beginners Mailing
        List - Discussion of primarily beginner-level topics related to
        Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] How would you implement Instant and
        Interval
Message-ID:
        <87y4eoniyq.fsf@chladni.i-did-not-set--mail-host-address--so-tickle-me>
        
Content-Type: text/plain

On 2015-10-27 at 13:53, martin <martin.drautzb...@web.de> wrote:
> Hello all
>
> If I define an Instant as a point in Time and an Interval as the difference 
> between two Instants, and I also want to use
> (+) and (-), how can I do this.
>
> My initial thought making them instances of the Num class, but that does not 
> work. (-) is okay on Intervals, but on
> Instant it returns a different type (Interval).
>
> Is it possible at all to define a typeclass with (-) :: Instant -> Instant -> 
> Interval without using language extensions?

I think you are asking for the same type class function to have
the types

`Instant -> Instant -> Interval`

and

`Interval -> Interval -> Interval`

for two different instances.  I don't believe this is possible without
language extensions.  Below is an example of doing it with
TypeFamilies.  If I actually wanted this, I'd probably use the Affine
class from linear[1] or vector-space[2] instead of the Sub class I
define here.  At any event, I don't think I'd want to give up on using -
in it's normal meaning of Num, in order to use it for Time and Interval.

newtype Time = Time Double deriving Show
newtype Interval = Interval Double deriving Show

class Sub a where
  type Diff a
  (.-.) :: a -> a -> Diff a

instance Sub Time where
  type Diff Time = Interval
  (Time a) .-. (Time b) = Interval (a - b)

instance Sub Interval where
  type Diff Interval = Interval
  (Interval a) .-. (Interval b) = Interval (a - b)

Footnotes: 
[1]  http://hackage.haskell.org/package/linear-1.20.2/docs/Linear-Affine.html

[2]  
http://hackage.haskell.org/package/vector-space-0.10.2/docs/Data-AffineSpace.html



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

Message: 4
Date: Wed, 28 Oct 2015 12:54:17 +1100
From: Manuel M T Chakravarty <c...@justtesting.org>
To: beginners@haskell.org
Subject: [Haskell-beginners] New chapter in Learning Haskell: fractal
        structures
Message-ID: <20a2666e-5194-456e-962e-3629f3bab...@justtesting.org>
Content-Type: text/plain; charset=utf-8

Our tutorial ?Learning Haskell? just gained a new fun chapter on visualising 
recursion with fractal structures:

  http://blog.haskellformac.com/blog/fractals-recursion-in-pictures

Happy Coding!
Manuel

PS: This is going to be a good one for anybody who wants to get their kids 
interested in programming, too.

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

Message: 5
Date: Wed, 28 Oct 2015 11:52:53 +0100
From: galeo...@tiscali.it
To: <beginners@haskell.org>
Subject: [Haskell-beginners] lists strange behaviour
Message-ID: <46e77e6767444119625810ea038f1...@tiscali.it>
Content-Type: text/plain; charset=UTF-8; format=flowed

Hello,
if I write down: [(x,y)|x<-[1..5],y<-[1..5]]
I obtain as expected:
[(1,1),(1,2),(1,3),(1,4),(1,5),(2,1),(2,2),(2,3),(2,4),(2,5),(3,1),(3,2),(3,3),(3,4),(3,5),(4,1),(4,2),(4,3),(4,4),(4,5),(5,1),(5,2),(5,3),(5,4),(5,5)]
If I write down: [(x,y)|x<-[1..5],y<-[1..5],x==5]
I obtain as expected:
[(1,1),(1,2),(1,3),(1,4),(1,5)]
but if I write: [(x,y)|x<-[1..5],y<-[1..5],x<-[1]]
I obtain:
[(1,1),(1,2),(1,3),(1,4),(1,5),(1,1),(1,2),(1,3),(1,4),(1,5),(1,1),(1,2),(1,3),(1,4),(1,5),(1,1),(1,2),(1,3),(1,4),(1,5),(1,1),(1,2),(1,3),(1,4),(1,5)]
Why?????
Thank you in advance.
Regards,
Maurizio


Connetti gratis il mondo con la nuova indoona:  hai la chat, le 
chiamate, le video chiamate e persino le chiamate di gruppo.
E chiami gratis anche i numeri fissi e mobili nel mondo!
Scarica subito l?app Vai su https://www.indoona.com/




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

Message: 6
Date: Wed, 28 Oct 2015 18:01:18 +0700
From: Kim-Ee Yeoh <k...@atamo.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] lists strange behaviour
Message-ID:
        <CAPY+ZdT2h7RJTgOTV=-z6782a=75nnt2vpk+qbdtdvbjzvf...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Wed, Oct 28, 2015 at 5:52 PM, <galeo...@tiscali.it> wrote:

> but if I write: [(x,y)|x<-[1..5],y<-[1..5],x<-[1]]
> I obtain:
>
> [(1,1),(1,2),(1,3),(1,4),(1,5),(1,1),(1,2),(1,3),(1,4),(1,5),(1,1),(1,2),(1,3),(1,4),(1,5),(1,1),(1,2),(1,3),(1,4),(1,5),(1,1),(1,2),(1,3),(1,4),(1,5)]
>

Others will chime in with a full answer soon.

Meanwhile, consider that

[(x,y)|x<-[1..5],y<-[1..5],x<-[1]]

(which is quite weird as a set-theoretic expression)

is Haskell-equivalent to

[(x,y)|_<-[1..5],y<-[1..5],x<-[1]]

Now consider

[(x,y)|y<-[1..5],x<-[1]]

which is [(1,1),(1,2),(1,3),(1,4),(1,5)] as you expect.

Separately, consider

[ a | _ <- [1..5], f a ]

where you can experiment with different values of f and a.

Putting together the pieces will give you an answer to your query.


-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20151028/059f3c42/attachment-0001.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 88, Issue 26
*****************************************

Reply via email to