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. Concrete instance of abstract class (Adrian May)
2. Re: Concrete instance of abstract class (Adrian May)
3. Re: Concrete instance of abstract class (David McBride)
4. Re: The Missing Arrow Function Strikes Back (Brent Yorgey)
----------------------------------------------------------------------
Message: 1
Date: Thu, 6 Jun 2013 00:08:46 +0800
From: Adrian May <[email protected]>
Subject: [Haskell-beginners] Concrete instance of abstract class
To: "[email protected]" <[email protected]>
Message-ID:
<cad-ubzhkooxvv7kzrgrkmvxn249jgiisztdkpmjjpfpj2w-...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Hi folks,
I just wrote this:
import Diagrams.Prelude
import Diagrams.Backend.Cairo
type Dia = Diagram Cairo R2
class Turtlish t where
pic :: t s -> Dia
state :: t s -> s
move :: s -> t s -> t s
(>>>),(+++) :: t s -> t s -> t s
x >>> y = x +++ move (state x) y
The idea is that s is a turtle state, t s contains such a state along with
a growing diagram, and >>> superimposes the diagrams after shuffling the
right hand t s around according to the s I extract from the left hand t s.
But I have different turtles planned. I want a regular turtle, a Sankey
turtle which also has a width, and we could imagine sub-turtles that only
had the angle or only the position. But in all cases, I think the above
class describes how I want to compose diagrams together. I already tried it
with monads but I'm now thinking that I want something like the above *
instead* of a monad.
So how do I use it to make a regular turtle? Maybe something like:
data TurtState = TurtState P2 CircleFrac
data TurtWorld s = TurtWorld Dia s
I know exactly what s is above but otherwise the kinds don't match below.
instance Turtlish TurtWorld where
pic (TurtWorld d _) = d
state (TurtWorld _ s) = s
(TurtWorld d1 _) +++ (TurtWorld d2 s2) =
TurtWorld (d1 `atop` d2) s2
move (pp,aa) (TurtWorld d (p,a)) = TurtWorld
(d # rotate aa # translate pp)
( (p # rotate aa + pp) , (a+aa) )
Naturally, it barfs over move saying:
Couldn't match type `s' with `(R2, t0)'
`s' is a rigid type variable bound by
the type signature for move :: s -> TurtWorld s -> TurtWorld s
at turtle.hs:20:3
In the pattern: (pp, aa)
In an equation for `move':
move (pp, aa) (TurtWorld d (p, a))
= TurtWorld
(d # rotate aa # translate pp) ((p # rotate aa + pp), (a +
aa))
In the instance declaration for `Turtlish TurtWorld'
because it hasn't a clue what (pp,aa) is and wants s totally generic
anyway.
But what am I supposed to do instead? Isn't it an everyday thing to use a
generic pattern with a specific type?
TIA,
Adrian.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130606/a408d072/attachment-0001.htm>
------------------------------
Message: 2
Date: Thu, 6 Jun 2013 00:17:49 +0800
From: Adrian May <[email protected]>
Subject: Re: [Haskell-beginners] Concrete instance of abstract class
To: "[email protected]" <[email protected]>
Message-ID:
<CAD-UbzFPFO=-4dt0amsok0bb7jx8bbjla3jpaqnuhwnj05d...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
BTW, I also tried adding:
class Turstateish s where
pos :: s -> R2
ang :: s -> CircleFrac
and guarding the instance declaration with it, but that doesn't work cos
I'd have to mention s in the instance declaration, and then the kinds would
go out of sync again.
Adrian.
On 6 June 2013 00:08, Adrian May <[email protected]> wrote:
> Hi folks,
>
> I just wrote this:
>
> import Diagrams.Prelude
> import Diagrams.Backend.Cairo
>
> type Dia = Diagram Cairo R2
>
> class Turtlish t where
> pic :: t s -> Dia
> state :: t s -> s
> move :: s -> t s -> t s
> (>>>),(+++) :: t s -> t s -> t s
> x >>> y = x +++ move (state x) y
>
> The idea is that s is a turtle state, t s contains such a state along
> with a growing diagram, and >>> superimposes the diagrams after shuffling
> the right hand t s around according to the s I extract from the left hand
> t s.
>
> But I have different turtles planned. I want a regular turtle, a Sankey
> turtle which also has a width, and we could imagine sub-turtles that only
> had the angle or only the position. But in all cases, I think the above
> class describes how I want to compose diagrams together. I already tried it
> with monads but I'm now thinking that I want something like the above *
> instead* of a monad.
>
> So how do I use it to make a regular turtle? Maybe something like:
>
> data TurtState = TurtState P2 CircleFrac
> data TurtWorld s = TurtWorld Dia s
>
> I know exactly what s is above but otherwise the kinds don't match below.
>
> instance Turtlish TurtWorld where
> pic (TurtWorld d _) = d
> state (TurtWorld _ s) = s
> (TurtWorld d1 _) +++ (TurtWorld d2 s2) =
> TurtWorld (d1 `atop` d2) s2
> move (pp,aa) (TurtWorld d (p,a)) = TurtWorld
> (d # rotate aa # translate pp)
> ( (p # rotate aa + pp) , (a+aa) )
>
> Naturally, it barfs over move saying:
>
> Couldn't match type `s' with `(R2, t0)'
> `s' is a rigid type variable bound by
> the type signature for move :: s -> TurtWorld s -> TurtWorld s
> at turtle.hs:20:3
> In the pattern: (pp, aa)
> In an equation for `move':
> move (pp, aa) (TurtWorld d (p, a))
> = TurtWorld
> (d # rotate aa # translate pp) ((p # rotate aa + pp), (a +
> aa))
> In the instance declaration for `Turtlish TurtWorld'
>
> because it hasn't a clue what (pp,aa) is and wants s totally generic
> anyway.
>
> But what am I supposed to do instead? Isn't it an everyday thing to use a
> generic pattern with a specific type?
>
> TIA,
> Adrian.
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130606/38e54d2f/attachment-0001.htm>
------------------------------
Message: 3
Date: Wed, 5 Jun 2013 13:02:52 -0400
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] Concrete instance of abstract class
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CAN+Tr40cao2QoBr_zEN0bX9PPL0FRuNLbmy=zxd-jej-hpd...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
If you can put any s into TurtWorld, then its instance can't assume
there is a pair there. If you want to make an instance that depends
on s being a pair, add it to the class by adding
MultiParamTypeClasses, FlexibleInstances and going:
instance (Angle a) => Turtlish TurtWorld (R2,a) where
pic (TurtWorld d _) = d
state (TurtWorld _ s) = s
(TurtWorld d1 _) +++ (TurtWorld d2 s2) =
TurtWorld (d1 `atop` d2) s2
move (pp,aa) (TurtWorld d (p,a)) = TurtWorld
(d # rotate aa # translate pp)
( (p # rotate aa + pp) , (a+aa)
There, now TurtWorld is an instance of Turtlish, but only when it has
a pair in its s position.
On Wed, Jun 5, 2013 at 12:17 PM, Adrian May
<[email protected]> wrote:
> BTW, I also tried adding:
>
> class Turstateish s where
> pos :: s -> R2
> ang :: s -> CircleFrac
>
> and guarding the instance declaration with it, but that doesn't work cos I'd
> have to mention s in the instance declaration, and then the kinds would go
> out of sync again.
>
> Adrian.
>
>
>
> On 6 June 2013 00:08, Adrian May <[email protected]> wrote:
>>
>> Hi folks,
>>
>> I just wrote this:
>>
>> import Diagrams.Prelude
>> import Diagrams.Backend.Cairo
>>
>> type Dia = Diagram Cairo R2
>>
>> class Turtlish t where
>> pic :: t s -> Dia
>> state :: t s -> s
>> move :: s -> t s -> t s
>> (>>>),(+++) :: t s -> t s -> t s
>> x >>> y = x +++ move (state x) y
>>
>> The idea is that s is a turtle state, t s contains such a state along with
>> a growing diagram, and >>> superimposes the diagrams after shuffling the
>> right hand t s around according to the s I extract from the left hand t s.
>>
>> But I have different turtles planned. I want a regular turtle, a Sankey
>> turtle which also has a width, and we could imagine sub-turtles that only
>> had the angle or only the position. But in all cases, I think the above
>> class describes how I want to compose diagrams together. I already tried it
>> with monads but I'm now thinking that I want something like the above
>> instead of a monad.
>>
>> So how do I use it to make a regular turtle? Maybe something like:
>>
>> data TurtState = TurtState P2 CircleFrac
>> data TurtWorld s = TurtWorld Dia s
>>
>> I know exactly what s is above but otherwise the kinds don't match below.
>>
>> instance Turtlish TurtWorld where
>> pic (TurtWorld d _) = d
>> state (TurtWorld _ s) = s
>> (TurtWorld d1 _) +++ (TurtWorld d2 s2) =
>> TurtWorld (d1 `atop` d2) s2
>> move (pp,aa) (TurtWorld d (p,a)) = TurtWorld
>> (d # rotate aa # translate pp)
>> ( (p # rotate aa + pp) , (a+aa) )
>>
>> Naturally, it barfs over move saying:
>>
>> Couldn't match type `s' with `(R2, t0)'
>> `s' is a rigid type variable bound by
>> the type signature for move :: s -> TurtWorld s -> TurtWorld s
>> at turtle.hs:20:3
>> In the pattern: (pp, aa)
>> In an equation for `move':
>> move (pp, aa) (TurtWorld d (p, a))
>> = TurtWorld
>> (d # rotate aa # translate pp) ((p # rotate aa + pp), (a +
>> aa))
>> In the instance declaration for `Turtlish TurtWorld'
>>
>> because it hasn't a clue what (pp,aa) is and wants s totally generic
>> anyway.
>>
>> But what am I supposed to do instead? Isn't it an everyday thing to use a
>> generic pattern with a specific type?
>>
>> TIA,
>> Adrian.
>>
>>
>>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 4
Date: Wed, 5 Jun 2013 15:09:32 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] The Missing Arrow Function Strikes
Back
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-1
Ah. Well, you can implement split and unsplit just as they are written
on that page. You can even make split nicer by implementing it as
split = id &&& id
which avoids the use of 'arr'. However, I don't really see much
practical point to 'split' (though it is nice theoretically).
Usually, when you split something you follow it up by applying more
arrows to both components of the tuple. But in that case you might as
well just write (f &&& g) in the first place, instead of split >>> (f
*** g).
-Brent
On Wed, Jun 05, 2013 at 10:46:10PM +0800, Adrian May wrote:
> Well I just read this:
>
> http://www.haskell.org/haskellwiki/Arrow_tutorial
>
> Adrian.
>
>
>
> On 5 June 2013 21:58, Brent Yorgey <[email protected]> wrote:
>
> > What are the types of 'split' and 'unsplit'? It is hard to guess what
> > you want just from their names.
> >
> > -Brent
> >
> > On Wed, Jun 05, 2013 at 01:02:40PM +0800, Adrian May wrote:
> > > Thanks Ertugrul. In the meantime I noticed that split and unsplit are
> > also
> > > missing. Is there a similar replacement for them?
> > >
> > > Adrian.
> > > On 5 Jun 2013 12:57, "Ertugrul S?ylemez" <[email protected]> wrote:
> > >
> > > > Adrian May <[email protected]> wrote:
> > > >
> > > > > I just banged up against this problem:
> > > > >
> > > > >
> > > >
> > http://haskell.1045720.n5.nabble.com/The-case-of-the-missing-Arrow-function-td3125388.html
> > > > >
> > > > > Was liftA2 (not the applicative one) a bad idea, or is there another
> > > > > way to do it, or what?
> > > >
> > > > That liftA2 (let me call it liftA2') likely has this type signature:
> > > >
> > > > liftA2' :: (Arrow cat)
> > > > => (b -> c -> d)
> > > > -> cat a b
> > > > -> cat a c
> > > > -> cat a d
> > > >
> > > > Does this sound familiar? You can write this function in terms of the
> > > > arrow combinators:
> > > >
> > > > liftA2' f c d = arr (uncurry f) . (c &&& d)
> > > >
> > > > However, if your arrow is also a family of applicative functors
> > > > (i.e. pretty much always),
> > > >
> > > > instance Applicative (MyArrow a)
> > > >
> > > > then it's probably a bad idea, because you really want to use the
> > > > cleaner liftA2 instead:
> > > >
> > > > liftA2 :: (Applicative f)
> > > > => (a -> b -> c)
> > > > -> f a
> > > > -> f b
> > > > -> f c
> > > >
> > > >
> > > > 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.
> > > >
> > > > _______________________________________________
> > > > Beginners mailing list
> > > > [email protected]
> > > > http://www.haskell.org/mailman/listinfo/beginners
> > > >
> > > >
> >
> > > _______________________________________________
> > > Beginners mailing list
> > > [email protected]
> > > http://www.haskell.org/mailman/listinfo/beginners
> >
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
> >
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 60, Issue 8
****************************************