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. Multi-param type classes and type dependency (Olivier Iffrig)
2. Re: Multi-param type classes and type dependency (David McBride)
3. Re: Multi-param type classes and type dependency (Olivier Iffrig)
4. FAQ: When to ask on Haskell-Beginners, when on Haskell-Cafe
(was haskell testing framework - missing htfpp) (Kim-Ee Yeoh)
5. Warsaw Haskell Group (Przemyslaw Kaminski)
6. Re: [Haskell-cafe] Will Haskell Platform 2012.4.0.0
uninstall cleanly for the installation of 2013.2.0.0
(Henk-Jan van Tuyl)
----------------------------------------------------------------------
Message: 1
Date: Fri, 12 Apr 2013 14:43:18 +0200
From: Olivier Iffrig <[email protected]>
Subject: [Haskell-beginners] Multi-param type classes and type
dependency
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Hello,
I'm trying to write some code which boils down to this idea : I have a
collection (Collection), and I want to play with some annotations (of any type)
to the items of the collection. I will often have only one collection and many
different annotation sets. What matters to me is to be able to have an
arbitrary index type (or at least instances of Ix) for the collection, and use
it with the annotations as well.
I've come to this code so far :
--------------------
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
-- Just for the example
data Thing = Foo | Bar deriving Show
-- A collection
-- i is the index type
-- c is the collection type
class Collection i c where
getThing :: c -> i -> Thing
-- A set of annotations on collection objects
-- a is an annotation type constructor (a y is an annotation of type y)
class Collection i c => Annotation i c a where
collection :: a y -> c -- access the underlying Collection
select :: a y -> i -> y -- select the annotation of an item given its index
-- My custom collection
data Things = Things [Thing] deriving Show
-- An annotation set based on a list
data MyAnnotation c y = Ann c [y]
instance Collection Int Things where
getThing (Things ts) i = ts !! i
instance Annotation Int Things (MyAnnotation Things) where
collection (Ann c _) = c
select (Ann _ as) i = as !! i
main = print $ select ann (2 :: Int) where
ts = Things [Foo, Bar, Foo, Foo]
ann = Ann ts ["a", "b", "c", "d"]
--------------------
This does not work (No instance for (Annotation Int c0 (MyAnnotation
Things)) arising from a use of `select'). I do not know how I can tell
the type system that c0 is Things here, if it is actually possible.
I'll appreciate any help or comments on how to rewrite this.
Cheers,
--
Olivier Iffrig
------------------------------
Message: 2
Date: Fri, 12 Apr 2013 09:39:59 -0400
From: David McBride <[email protected]>
Subject: Re: [Haskell-beginners] Multi-param type classes and type
dependency
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<can+tr41d+rq2gxfq_fyzq7nj16jbhlgtacd8fdpbhd81dkc...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
I don't know if this is the most advisable way to go about things, but if
you add the FunctionalDependencies extension you can do this:
class Collection i c => Annotation i c a | a -> c where
And then it compiles and runs and I assume gives the right answer.
On Fri, Apr 12, 2013 at 8:43 AM, Olivier Iffrig <[email protected]> wrote:
> Hello,
>
> I'm trying to write some code which boils down to this idea : I have a
> collection (Collection), and I want to play with some annotations (of any
> type)
> to the items of the collection. I will often have only one collection and
> many
> different annotation sets. What matters to me is to be able to have an
> arbitrary index type (or at least instances of Ix) for the collection, and
> use
> it with the annotations as well.
>
> I've come to this code so far :
>
> --------------------
> {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
>
> -- Just for the example
> data Thing = Foo | Bar deriving Show
>
> -- A collection
> -- i is the index type
> -- c is the collection type
> class Collection i c where
> getThing :: c -> i -> Thing
>
> -- A set of annotations on collection objects
> -- a is an annotation type constructor (a y is an annotation of type y)
> class Collection i c => Annotation i c a where
> collection :: a y -> c -- access the underlying Collection
> select :: a y -> i -> y -- select the annotation of an item given its
> index
>
>
> -- My custom collection
> data Things = Things [Thing] deriving Show
>
> -- An annotation set based on a list
> data MyAnnotation c y = Ann c [y]
>
> instance Collection Int Things where
> getThing (Things ts) i = ts !! i
>
> instance Annotation Int Things (MyAnnotation Things) where
> collection (Ann c _) = c
> select (Ann _ as) i = as !! i
>
> main = print $ select ann (2 :: Int) where
> ts = Things [Foo, Bar, Foo, Foo]
> ann = Ann ts ["a", "b", "c", "d"]
> --------------------
>
> This does not work (No instance for (Annotation Int c0 (MyAnnotation
> Things)) arising from a use of `select'). I do not know how I can tell
> the type system that c0 is Things here, if it is actually possible.
>
> I'll appreciate any help or comments on how to rewrite this.
>
> Cheers,
>
> --
> Olivier Iffrig
>
>
> _______________________________________________
> 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/20130412/fae50f62/attachment-0001.htm>
------------------------------
Message: 3
Date: Fri, 12 Apr 2013 15:57:40 +0200
From: Olivier Iffrig <[email protected]>
Subject: Re: [Haskell-beginners] Multi-param type classes and type
dependency
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
David McBride wrote (2013-04-12 09:39:59 -0400):
> I don't know if this is the most advisable way to go about things, but if
> you add the FunctionalDependencies extension you can do this:
>
> class Collection i c => Annotation i c a | a -> c where
Thanks for the advice.
I already tried functional dependencies, but not like that. As far as I
understand how they work, this notation means c is uniquely determined
by a, but I would prefer beign able to handle generic annotation types,
which apply to several collections.
I also came up with a working solution using existential quantification,
but my understanding of it is quite limited so I don't know if it is a
good idea:
data AnyCollection i = forall c. (Collection i c) => Coll c
class Annotation i a where
collection :: a y -> AnyCollection i -- access the underlying Collection
select :: a y -> i -> y -- select the annotation of an item given its index
instance Annotation Int (MyAnnotation Things) where
collection (Ann c _) = Coll c
select (Ann _ as) i = as !! i
--
Olivier
------------------------------
Message: 4
Date: Sat, 13 Apr 2013 02:29:31 +0700
From: Kim-Ee Yeoh <[email protected]>
Subject: [Haskell-beginners] FAQ: When to ask on Haskell-Beginners,
when on Haskell-Cafe (was haskell testing framework - missing htfpp)
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CAPY+ZdRvmApnE-hxkRrXyJYQPAb=htlhghgu1qoxmslyn7s...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
On Thu, Apr 11, 2013 at 10:50 PM, Chadda? Fouch?
<[email protected]> wrote:
> More probably you should rather have asked this on Haskell-Cafe, it's not
> really a beginner question. htfpp sounds like a pre processor
The short answer is: if your question falls within the scope of LYAH,
then it belongs here.
If it's package specific (wxhaskell, htfpp), you're probably better
off on the bigger list.
Understandably, there's a huge gap between the two. The rule of thumb
I'd use (and this is certainly not without controversy) is: when in
doubt use Cafe.
-- Kim-Ee
------------------------------
Message: 5
Date: Fri, 12 Apr 2013 21:42:40 +0000
From: Przemyslaw Kaminski <[email protected]>
Subject: [Haskell-beginners] Warsaw Haskell Group
To: [email protected]
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Hello!
We are organizing a group of Haskell fans from Warsaw, Poland. So far we
have set up a community on G+
(https://plus.google.com/u/0/communities/103183708602453146804), a
mailing list is on the way.
We would like to meet regularly someplace in the capital (we still
decide where), and hack on Haskell together as much as we can :)
Should there be more people involved, we could arrange regular lectures.
Hope to see you there!
Warsaw Haskell Group
------------------------------
Message: 6
Date: Fri, 12 Apr 2013 23:54:49 +0200
From: "Henk-Jan van Tuyl" <[email protected]>
Subject: Re: [Haskell-beginners] [Haskell-cafe] Will Haskell Platform
2012.4.0.0 uninstall cleanly for the installation of 2013.2.0.0
To: "Haskell Beginners" <[email protected]>, haskell-cafe
<[email protected]>, KC <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
delsp=yes
On Fri, 12 Apr 2013 00:42:15 +0200, KC <[email protected]> wrote:
> :)
You don't really need to uninstall the platform, unless your disk is
running out of space; just change your search path (that's actually done
automatically at installation time). If you keep the old platform, you can
test your latest (versions of) packages with a previous compiler. Note,
that re-installing an old platform may cause a lot of trouble, because
cabal-install might select incompatible versions of packages.
Regards,
Henk-Jan van Tuyl
--
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 58, Issue 26
*****************************************