RE: [Haskell] Typeable and Data instances for Double, FiniteMap, ...

2005-01-18 Thread Simon Peyton-Jones
| Yes, once you start to use the SYB library you end up wanting it to
| cover almost all your types.
| I will make an effort *now* hoping that all the instance can still
make
| it into GHC 6,4.
| (There are indeed a few more unsupported types that make obviously
sense.)

Yes, anything in the HEAD will get into 6.4

Simon

___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


Re: [Haskell] Typeable and Data instances for Double, FiniteMap, ...

2005-01-18 Thread Ralf Laemmel
Georg Martius wrote:
I was playing around with "Scap you Boilerplate" and realised some 
missing instances of Typeable and Data. Is there a particular reason 
why there is no Data Double instance? 
There has been a Double instance under CVS (GHC HEAD) since March 2004.
It will be included in GHC 6.4.
(BTW, this email should go to glasgow-haskell-users perhaps?)
Furthermore I was wondering why no instance for the collection types 
such as FiniteMap, Set and HashTable is provided.
Yes, once you start to use the SYB library you end up wanting it to 
cover almost all your types.
I will make an effort *now* hoping that all the instance can still make 
it into GHC 6,4.
(There are indeed a few more unsupported types that make obviously sense.)

I looked at the library source-code (GHC) and reallised that there is 
really much documenting comments in, but which are not Haddock 
comments. Again I don't understand that. Is the programmer supposed to 
look at the source-code rather the API documentation? 
I wonder how other Haskellers think of that.
I tend to use non-Haddock comments whenever I want to document 
*implementation details*.
Is there an idiom for that; so that people get not confused?

Regards,
Ralf
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


RE: [Haskell] Typeable and Data instances for Double, FiniteMap, ...

2005-01-18 Thread Simon Peyton-Jones
| I was playing around with "Scap you Boilerplate" and realised some
missing instances of Typeable and
| Data. Is there a particular reason why there is no Data Double
instance?
| Furthermore I was wondering why no instance for the collection types
such as FiniteMap, Set and
| HashTable is provided. At the end of the mail [1] there is my
implementation of instances for at least
| Double and FiniteMap.

I've asked Ralf if he'll add them.

| Apart from that I looked at the library source-code (GHC) and
reallised that there is really much
| documenting comments in, but which are not Haddock comments. Again I
don't understand that. Is
| the programmer supposed to look at the source-code rather the API
documentation?

It should be Haddock'd.  We'd be delighted if anyone was willing to
transfer code in comments to Haddock comments, where that is
appropriate, and probably add new Haddock comments where necessary.  

Any volunteers?   We'd give CVS access...

Simon


___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


[Haskell] Typeable and Data instances for Double, FiniteMap, ...

2005-01-16 Thread Georg Martius
Hi,
I was playing around with "Scap you Boilerplate" and realised some missing 
instances of Typeable and Data. Is there a particular reason why there is no Data Double 
instance?
Furthermore I was wondering why no instance for the collection types such as 
FiniteMap, Set and HashTable is provided. At the end of the mail [1] there is 
my implementation of instances for at least Double and FiniteMap.
Apart from that I looked at the library source-code (GHC) and reallised that 
there is really much documenting comments in, but which are not Haddock 
comments. Again I don't understand that. Is the programmer supposed to look at 
the source-code rather the API documentation?
Regards,
 Georg
[1] instances: Data Double, Typeable FiniteMap, Data FiniteMap
--
-- Data instance for Double.
--  IMHO It should be added as a basic type to Data.Constr with DoubleConstr 
like Float
doubleConstr :: Double -> Constr
doubleConstr x = mkConstr 1 (show x) Prefix
doubleDataType :: DataType
doubleDataType = mkDataType [doubleConstr 0.0]
instance Data Double where
 toConstr x = doubleConstr x
 fromConstr c = read $ conString c
 dataTypeOf _ = doubleDataType

--
-- Typeable instance for FiniteMap
fmTc :: TyCon
fmTc = mkTyCon "FM"
instance (Typeable a, Typeable b) =>  Typeable (FiniteMap a b) where
   typeOf fm = mkAppTy fmTc [typeOf ((undefined :: FiniteMap a b -> a) fm)]
--
-- Data instance for FiniteMap
--  treats the FiniteMap as a list.
--  More performant solutions might be possible,
--   if internal of FM can be exploited
fmConstr :: Constr
fmConstr = mkConstr 1 "FM" Prefix
fmDataType :: DataType
fmDataType = mkDataType [fmConstr]
instance (Data a, Data b, Ord a) => Data (FiniteMap a b) where
 gfoldl f z fm = z listToFM `f` (fmToList fm)
 toConstr _= fmConstr
 fromConstr c = case conIndex c
of 1 -> emptyFM
 dataTypeOf _ = fmDataType
--
 Georg Martius,  Tel: (+49 34297) 89434 
--- http://www.flexman.homeip.net -
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell