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. Is there a way to hide an existing data type so that I can
use my own version? (Costello, Roger L.)
2. Re: Is there a way to hide an existing data type so that I
can use my own version? (Henk-Jan van Tuyl)
3. Re: Is there a way to hide an existing data type so that I
can use my own version? (Costello, Roger L.)
4. XmlPickler on ADT (Tim Perry)
----------------------------------------------------------------------
Message: 1
Date: Tue, 31 Jul 2012 11:08:38 +0000
From: "Costello, Roger L." <[email protected]>
Subject: [Haskell-beginners] Is there a way to hide an existing data
type so that I can use my own version?
To: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="us-ascii"
Hi Folks,
For learning purposes, I created an "Either" data type:
data Either a b = Left a | Right b
deriving (Show)
However, when I try to use Left (or Right), I get an error message saying that
it is ambiguous whether I am using Prelude.Left or Main.Left
So I tried hiding Prelude.Either like so:
import Prelude hiding Either
But that produced an error.
Is there a way to hide the existing Either data type so that I can use my own
version?
/Roger
------------------------------
Message: 2
Date: Tue, 31 Jul 2012 13:18:42 +0200
From: "Henk-Jan van Tuyl" <[email protected]>
Subject: Re: [Haskell-beginners] Is there a way to hide an existing
data type so that I can use my own version?
To: "[email protected]" <[email protected]>, "Costello, Roger
L." <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
delsp=yes
On Tue, 31 Jul 2012 13:08:38 +0200, Costello, Roger L.
<[email protected]> wrote:
> import Prelude hiding Either
That should be:
import Prelude hiding (Either)
Regards,
Henk-Jan van Tuyl
--
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--
------------------------------
Message: 3
Date: Tue, 31 Jul 2012 11:26:29 +0000
From: "Costello, Roger L." <[email protected]>
Subject: Re: [Haskell-beginners] Is there a way to hide an existing
data type so that I can use my own version?
To: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="us-ascii"
Ah, excellent. Thanks Henk-Jan.
This works perfectly:
--------------------------------------------------------
import Prelude hiding (Either, Left, Right)
data Either a b = Left a | Right b
deriving (Show)
--------------------------------------------------------
/Roger
-----Original Message-----
From: Henk-Jan van Tuyl [mailto:[email protected]]
Sent: Tuesday, July 31, 2012 7:19 AM
To: [email protected]; Costello, Roger L.
Subject: Re: [Haskell-beginners] Is there a way to hide an existing data type
so that I can use my own version?
On Tue, 31 Jul 2012 13:08:38 +0200, Costello, Roger L.
<[email protected]> wrote:
> import Prelude hiding Either
That should be:
import Prelude hiding (Either)
Regards,
Henk-Jan van Tuyl
--
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--
------------------------------
Message: 4
Date: Tue, 31 Jul 2012 10:55:17 -0700
From: Tim Perry <[email protected]>
Subject: [Haskell-beginners] XmlPickler on ADT
To: Haskell Beginners <[email protected]>
Message-ID:
<CAFVgASUSHNmfcB2yeGnirSRifBWcyD=dqm8voxumo4vhzcz...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Hi everyone,
I'm trying to learn to write XmlPicklers. I've been trying to follow the
tutorial on the HaskelWiki, but it doesn't quite cover an issue I've run
into.
http://www.haskell.org/haskellwiki/HXT/Conversion_of_Haskell_data_from/to_XML
I have a ADTs like so:
data Plant = Plant
{ renewables :: [Renewable]
, rewewableMonthly :: [RenewableMonthly]
, waterHeating :: [WaterHeating]
, hvac :: [HVAC]
} deriving (Read, Show, Eq)
data Renewable = Renewable
{ dcRating :: Double -- kW
, annualTDV :: Double -- CA Energy Comm. TDV
} deriving (Read, Show, Eq)
data RenewableMonthly = RenewableMonthly
{ month :: Int
, cost :: Double
, demand :: Double
, energy :: Double
} deriving (Read, Show, Eq)
data WaterHeating = WaterHeating
{ whName :: String -- name for reference purposes.
, whQuantity :: Int
...
data HVAC = HVAC
{ slaStatus :: String -- Specific leakage area
construction type.
, newCFM50 :: Double -- New building leakage in
cubic feet per minute.
, existCFM50 :: Double
I want to use an XmlPickler to read and write this. The XML looks like
this:
<Plant>
<Renewables DCRating="8.4" AnnualTDV="0" />
<RenewableMonthly Month="1" Cost="0" Demand="0" Energy="0" />
<RenewableMonthly Month="2" Cost="0" Demand="0" Energy="0" />
<RenewableMonthly Month="3" Cost="0" Demand="0" Energy="0" />
<RenewableMonthly Month="4" Cost="0" Demand="0" Energy="0" />
<RenewableMonthly Month="5" Cost="0" Demand="0" Energy="0" />
<RenewableMonthly Month="6" Cost="0" Demand="0" Energy="0" />
<RenewableMonthly Month="7" Cost="0" Demand="0" Energy="0" />
<RenewableMonthly Month="8" Cost="0" Demand="0" Energy="0" />
<RenewableMonthly Month="9" Cost="0" Demand="0" Energy="0" />
<RenewableMonthly Month="10" Cost="0" Demand="0" Energy="0" />
<RenewableMonthly Month="11" Cost="0" Demand="0" Energy="0" />
<RenewableMonthly Month="12" Cost="0" Demand="0" Energy="0" />
<WaterHeating Name="Daikin Altherma HP" Quantity="1"
ConstructionStatus="New" EnergyFactor="2.344" SolarFraction="0" ....
<HVAC SLAStatus="New" NewCFM50="0" ExistCFM50="0"
NewSLA="4.9000000953674316" ExistSLA="4.9" DuctStatus="New" ....
<Zone ...
Running my code I get an error:
-- (1) readDocument: start processing document "1101_11-001 Walsh.xml" --
(1) getXmlContents: content read and decoded for
"file:///fairoaks1/all_proj/1101%20PG&E%20CAHP%2011-12/CRM/EProDataExtractPlanning/XML%20samples/1101_11-001%20Walsh.xml"
-- (1) getXmlContents' -- (1) readDocument: "1101_11-001 Walsh.xml" (mime
type: "text/xml" ) will be processed -- (1) readDocument: "1101_11-001
Walsh.xml" processed
fatal error: document unpickling failed
xpCheckEmptyContents: unprocessed XML content detected context: element
"Plant" contents:
Is it possible to write an XmlPickler for this? Do I need to make
Renewable, RenewableMonthly, WaterHeating, and HVAC all the same type with
4 constructors and use xpAlt? Ideas?
Thanks,
Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120731/0b81abff/attachment.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 49, Issue 34
*****************************************