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. Re: Fwd: Functional Dependencies (Stephen Tetley)
2. Re: Fwd: Functional Dependencies (Brent Yorgey)
3. Using derived Show most of the time (Russ Abbott)
4. Linking modules (Russ Abbott)
5. Re: Linking modules (Chadda? Fouch?)
6. Re: Using derived Show most of the time (Brent Yorgey)
----------------------------------------------------------------------
Message: 1
Date: Sat, 11 Dec 2010 12:54:22 +0000
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Fwd: Functional Dependencies
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi Dan
I'm not convinced double flattening has a regular type that can be
translated into a type class.
My suspicion is that double flattenable things are nested types not
regular types, though to convince myself I'd have to work it out on
paper which might take some time.
I'd be tempted to avoid a type class for the moment and craft some
non-overloaded double flattening functions and check how regular their
types are.
Regards
Stephen
------------------------------
Message: 2
Date: Sat, 11 Dec 2010 10:18:33 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Fwd: Functional Dependencies
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Fri, Dec 10, 2010 at 11:22:08PM -0800, dan portin wrote:
> Hi,
>
> *unflt* was a poor choice of name. *flt2*, which flattens a datatype
> containing a flattenable datatype, would have been a better name.
>
> >
> > If I was making a flatten class, I wouldn't want Monad as a constraint
> > on the result container. Monad doesn't really say anything about
> > "containers" - there are some containers that are Monads, but there
> > are monads that aren't containers and there are containers that aren't
> > monads.
> >
>
> You're right. My initial class was
>
> class Monoid m => t -> m where
> flt :: t -> m
>
> instance (Tree a) [a] where flt = fltTree
> instance (Maybe a) [a] where flt = maybeToList
It sounds a lot like you want the "Foldable" class from Data.Foldable.
Is that what you are looking for? If not, can you explain the
particular way in which Foldable does not meet your needs?
-Brent
------------------------------
Message: 3
Date: Sat, 11 Dec 2010 08:45:22 -0800
From: Russ Abbott <[email protected]>
Subject: [Haskell-beginners] Using derived Show most of the time
To: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
I have a data type for which I want to generate my own show string in a few
cases, e.g.,
*data *T = T1 ...
| T2 ...
| T3 ...
...
I'd like to do something like this,
*instance *Show T *where*
show T5 ... = <something special>
show t = showTheDerived t
Is there a way to do something like that simply?
*
-- Russ *
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20101211/a91ace6e/attachment-0001.htm>
------------------------------
Message: 4
Date: Sat, 11 Dec 2010 10:37:01 -0800
From: Russ Abbott <[email protected]>
Subject: [Haskell-beginners] Linking modules
To: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
I have two modules Structure and Component. Module Structure defines
data Structure = Component ...
Module Component defines
data Component = ...
I would like Structure to import Component. But Component
includes functions that take a Structure as an argument. So I have (or would
like) something like this organization.
Module Structure where
import Component
data Structure = Component ...
Module Component where
data Component = ...
f :: Structure -> Component ->Structure
The functions in Component are really very Component related and should not
be moved to Structure. So how can I set up this circular relationship?
I thought that one approach would be to do something like the following. But
when I try I get all fouled up. Help would be appreciated.
Module Structure where
class Comp
data Structure = Comp ...
Module Component where
import Structure
data Component = ...
instance Comp Component
If I do this I get a complaint that class Comp needs a type parameter. If I
give it an artificial one, that leads to all sorts of other problems. Is
there a better way?
Thanks.
*
-- Russ *
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20101211/24a1e5d7/attachment-0001.htm>
------------------------------
Message: 5
Date: Sat, 11 Dec 2010 20:56:23 +0100
From: Chadda? Fouch? <[email protected]>
Subject: Re: [Haskell-beginners] Linking modules
To: [email protected]
Cc: beginners <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Sat, Dec 11, 2010 at 7:37 PM, Russ Abbott <[email protected]> wrote:
> I have two modules Structure and Component. ?Module Structure defines
> ?? ? data Structure = Component ...
> Module Component defines
> ?? ?data Component = ...
> I would like Structure to import Component. ?But Component
> includes?functions?that take a Structure as an argument. So I have (or would
> like) something like this organization.
>
> [snip]
>
> The functions in Component are really very Component related and should not
> be moved to Structure. So how can I set up this circular relationship?
GHC allows you to compile mutually recursive modules, see
http://www.haskell.org/ghc/docs/latest/html/users_guide/separate-compilation.html#mutual-recursion
for how to do it.
--
Jeda?
------------------------------
Message: 6
Date: Sat, 11 Dec 2010 15:31:05 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Using derived Show most of the time
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Sat, Dec 11, 2010 at 08:45:22AM -0800, Russ Abbott wrote:
> I have a data type for which I want to generate my own show string in a few
> cases, e.g.,
>
> *data *T = T1 ...
> | T2 ...
> | T3 ...
> ...
>
>
> I'd like to do something like this,
>
> *instance *Show T *where*
> show T5 ... = <something special>
> show t = showTheDerived t
>
>
> Is there a way to do something like that simply?
Unfortunately, there isn't quite. There are two solutions that I can
think of, both slightly sub-optimal:
(1) Just derive the normal Show instance for T. Then make a newtype
wrapper around T,
newtype NiceT = NiceT T
and give T2 a show instance like
instance Show T2 where
show (NiceT (T5 ...)) = <something special>
show (NiceT t) = show t
that way when you want a T shown specially you can wrap it in a
NiceT constructor.
(2) Make a new type class
class Pretty p where
ppr :: p -> String
and write an instance of it for T in terms of T's derived Show
instance. This solution satisfies those people who argue that Show
should always print out valid Haskell expressions that could be,
say, pasted into ghci (and I admit to leaning in that direction
personally) and using a different class for human-readable,
pretty-printed representations. But of course the nice thing about
Show is that it gets used automatically for values in ghci, and with
this solution you have to explicitly wrap things in calls to ppr.
-Brent
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 30, Issue 16
*****************************************