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.  Hexpat: GeneriXMLString instances not    recognized?
      (Aleksandar Dimitrov)
   2.  Re: [Haskell-cafe] running and understanding a   lifting
      program  (Bastian Erdn??)


----------------------------------------------------------------------

Message: 1
Date: Mon, 25 Oct 2010 00:08:37 +0200
From: "Aleksandar Dimitrov" <[email protected]>
Subject: [Haskell-beginners] Hexpat: GeneriXMLString instances not
        recognized?
To: "Haskell Beginners" <[email protected]>
Message-ID: <op.vk3o4m0ejdv...@minsk>
Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes

Hi list,

I'm trying to use Hexpat to efficiently SAX-parse an XML document (of  
quite some size.) So I figured it'd be a good idea to use Data.Text as the  
string type for my parsed XML data. It seems Hexpat's sax-parse function  
only accepts files in ByteString format, which is fair enough, but here's  
the really weird thing: the following line yields a compilation error!

> import Text.XML.Expat.SAX
> import qualified Data.Text as T
> import qualified Data.ByteString.Lazy as L
>main = do f <- L.readFile someFile
>           let x = parse defaultParseOptions f :: [SAXEvent T.Text T.Text]
> ...

The error:
     No instance for (GenericXMLString T.Text)
       arising from a use of `parse' at Polyparse.hs:15:12-38
     Possible fix:
       add an instance declaration for (GenericXMLString T.Text)
     In the expression:
           parse defaultParseOptions f :: [SAXEvent T.Text T.Text]

That's mighty strange, seeing as there is an instance for GenericXMLString  
Data.Text.Text in hexpat's source code (indeed, it's one of its advertised  
features!) Here is the documentation (as well as the source:
http://hackage.haskell.org/packages/archive/hexpat/0.19.4/doc/html/Text-XML-Expat-SAX.html#t:GenericXMLString

I went ahead and tried copying the instance declaration from the source to  
my own code. I noticed it didn't compile, since the type signature of  
peekByteStringLen (called from the Text instance declaration for  
GenericXMLString) clashed with the function's use of  
ByteString.Internal.ByteString (the type signature specified whatever  
ByteString Data.ByteString exports.)

Now my question is twofold: what am I overlooking? Why didn't it compile?  
I can install and compile the very same code easily via cabal, but it  
doesn't compile inside my program. Is there some magic at work that I  
missed? Secondly, why doesn't ghc recognize the instance declaration  
GenericXMLString Data.Text.Text, when it really should? (It does recognize  
the declaration for String!)

Thanks for any pointers!
Aleks


------------------------------

Message: 2
Date: Mon, 25 Oct 2010 15:05:54 +0200
From: Bastian Erdn?? <[email protected]>
Subject: [Haskell-beginners] Re: [Haskell-cafe] running and
        understanding a lifting program 
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii


On Oct 24, 2010, at 15:12, Patrick Browne wrote:

> hi,
> I am trying to run and understand a lifting program from [1].
> The program lifts points to moving points that vary their position over
> time.
> I made some effort to run the progrm but I do not know how to overide
> the +,-,*,sqr, and sqrt from the Num class. Below is my current attempt.
> 
> I do not wish to change or imporve the code, rather I wish to understand
> it as it stands and find out what needs to be added to get the outputs
> shown below i.e. distance between points p1 and p2 --> 1.55  and the
> distance between moving points mp1 and mp2  for time 2 ----> 5.83.

I got pretty close with

{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}

import Prelude hiding ((+), (-), (*), sqrt)
import qualified Prelude

data Point a = Point a a
type Time = Float

type Changing v = Time -> v

lift0 a = \t -> a
lift1 op a = \t -> op (a t)
lift2 op a b = \t -> op (a t) (b t)

class PlusMinus a where
  (+), (-) :: a -> a -> a

instance PlusMinus Float where
  (+) = (Prelude.+)
  (-) = (Prelude.-)

instance PlusMinus s => PlusMinus (Point s) where
  (+) (Point x y) (Point x' y') = Point (x+x') (y+y')
  (-) (Point x y) (Point x' y') = Point (x-x') (y-y')

class PlusMinus a => Number a where
  (*) :: a -> a -> a
  sqr, sqrt :: a -> a
  sqr a = a * a

instance Number Float where
  (*) = (Prelude.*)
  sqrt = Prelude.sqrt

class Number s => Points s where
  x, y :: Point s -> s
  x (Point x' y') = x'
  y (Point x' y') = y'
  dist :: Point s -> Point s -> s
  dist (Point x y) (Point x' y') = sqrt $ sqr (x-x') + sqr (y-y')

instance Points Float

instance PlusMinus v => PlusMinus (Changing v) where
  (+) = lift2 (+)
  (-) = lift2 (-)

instance Number v => Number (Changing v) where
  (*) = lift2 (*)
  sqrt = lift1 sqrt

instance Points (Changing Float)

> [1] A Mathematical Tool to Extend 2D Spatial Operations
> to Higher Dimensions:  by Farid Karimipour1,2, Mahmoud R. Delavar1, and
> Andrew U. Frank2
> 
> http://books.google.ie/books?id=JUGpGN_jwf0C&pg=PA153&lpg=PA153&dq=Karimipour+%22A+Mathematical+Tool+to+Extend+2D+Spatial+Operations+to+Higher+Dimensions%22&source=bl&ots=fu-lSkPMr3&sig=ztkcRV3Cv6hn9T6iwQCJ9sB75IM&hl=en&ei=QS7ETJHPGoiA5Ab0zZW6Aw&sa=X&oi=book_result&ct=result&resnum=4&ved=0CCMQ6AEwAw#v=onepage&q=Karimipour%20%22A%20Mathematical%20Tool%20to%20Extend%202D%20Spatial%20Operations%20to%20Higher%20Dimensions%22&f=false

Cheers,
Bastian

------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 28, Issue 37
*****************************************

Reply via email to