Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  A try on a bank machine algorithm... (Bernhard Lehnert)
   2. Re:  A try on a bank machine algorithm... (Thomas Friedrich)
   3.  HaL4: Haskell-Meeting in Germany, 12th June 2009
      (Janis Voigtlaender)
   4.  Re: [Haskell-cafe] HaL4: Haskell-Meeting in      Germany, 12th
      June 2009 (Janis Voigtlaender)
   5.  Type Class question (Malik H)
   6. Re:  Type Class question (Brent Yorgey)
   7.  HaXML tutorial (aditya siram)
   8.  HXT runtime error (aditya siram)
   9.  Re: HXT runtime error (aditya siram)


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

Message: 1
Date: Mon, 01 Jun 2009 19:27:47 +0200
From: Bernhard Lehnert <b.lehn...@gmx.de>
Subject: Re: [Haskell-beginners] A try on a bank machine algorithm...
To: beginners <beginners@haskell.org>
Message-ID: <1243877267.4144.9.ca...@sol>
Content-Type: text/plain; charset="UTF-8"

Hi,

> Ok, I don't really think I know what you are planing to do. 
> cashout 175 [200,100,50,20,10,5] == [0,1,1,1,0,1]


> It sounded to me a little different: like if you withdraw 200 €, you
> don't just want a 200 € bill, you want some small bills too: so you
> would get two 5s, two 10s, a 20, a 50, and a 100.

thank you so far. Yes, Brent, you are right. I wanted to do what my
program does, and moreover become a better Haskell programmer. So even
if I could not explain myself to Thomas on the first attempt, I honestly
like to study his very short and efficient code in my attempt to get a
feeling for "good" code. 

Thanks for all your help,
Bernhard



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

Message: 2
Date: Mon, 01 Jun 2009 13:58:09 -0400
From: Thomas Friedrich <i...@suud.de>
Subject: Re: [Haskell-beginners] A try on a bank machine algorithm...
To: Bernhard Lehnert <b.lehn...@gmx.de>
Cc: beginners <beginners@haskell.org>
Message-ID: <4a2416b1.90...@suud.de>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed


> like to study his very short and efficient code in my attempt to get a
> feeling for "good" code. 
>
>   

Now I feel embarrassed.  I should therefore mention that it is in fact 
not a very good idea to let the code crash, whenever its not able to 
cash out any money.  I mean that would be a really bad idea.  In such a 
case, you might want to wrap the whole thing with the Maybe monad.

import Control.Monad

saverCashout :: (Integral a) => a -> [a] -> Maybe [a]
saverCashout 0 _  = Just []
saverCashout _ [] = Nothing
saverCashout tocash (b:bs) = liftM (fst r :) (saverCashout (snd r) bs)
    where r = tocash `divMod` b


I was just lazy in the other code.

*Main> saverCashout 755 [50,100,50,5]
Just [15,0,0,1]
*Main> saverCashout 801 [50,100,50,5]
Nothing


Thomas



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

Message: 3
Date: Tue, 02 Jun 2009 13:18:00 +0200
From: Janis Voigtlaender <vo...@tcs.inf.tu-dresden.de>
Subject: [Haskell-beginners] HaL4: Haskell-Meeting in Germany, 12th
        June 2009
To: haskell <hask...@haskell.org>,      Haskell-Cafe
        <haskell-c...@haskell.org>, beginners@haskell.org
Message-ID: <4a250a68.9040...@tcs.inf.tu-dresden.de>
Content-Type: text/plain; charset=us-ascii; format=flowed

Hi all,

If you are anyway near Halle/Saale in June, be sure not to miss out on:

   http://iba-cg.de/hal4.html

We have already close to 50 registered participants, so expect a very
lively meeting. See you there? (Late registration still possible.)

Ciao,
Janis.

-- 
Dr. Janis Voigtlaender
http://wwwtcs.inf.tu-dresden.de/~voigt/
mailto:vo...@tcs.inf.tu-dresden.de


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

Message: 4
Date: Tue, 02 Jun 2009 13:21:17 +0200
From: Janis Voigtlaender <vo...@tcs.inf.tu-dresden.de>
Subject: [Haskell-beginners] Re: [Haskell-cafe] HaL4: Haskell-Meeting
        in      Germany, 12th June 2009
To: haskell <hask...@haskell.org>
Cc: beginners@haskell.org, Haskell-Cafe <haskell-c...@haskell.org>
Message-ID: <4a250b2d.8090...@tcs.inf.tu-dresden.de>
Content-Type: text/plain; charset=us-ascii; format=flowed

Janis Voigtlaender wrote:
> Hi all,
> 
> If you are anyway near Halle/Saale in June, be sure not to miss out on:

I meant "anywhere near", of course :-)

And even if you are not anyway or anywhere near, you might still want to
come just for the occasion :-)

-- 
Dr. Janis Voigtlaender
http://wwwtcs.inf.tu-dresden.de/~voigt/
mailto:vo...@tcs.inf.tu-dresden.de



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

Message: 5
Date: Tue, 2 Jun 2009 15:44:48 -0400
From: Malik H <mha...@gmail.com>
Subject: [Haskell-beginners] Type Class question
To: beginners@haskell.org
Message-ID:
        <648da0750906021244g475a0208i5e6108b9e9097...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

I am reading article "Fun with type functions" and I have a few
questions regarding examples presented in it. Here is the code

class Add a b where
    type SumTy a b
    add :: a -> b -> SumTy a b

instance (Add Integer a) => Add Integer [a] where
    type SumTy Integer [a] = [SumTy Integer a]
    add x y = map (add x) y

Here are my questions:
1. Is type "SumTy Integer [a]" visible outside 'Add' instance?
2. If yes, how would you create and instance of that type without
using 'add' function?
3. Will function 'add x y' create the following structure [SumTy x y1,
SumTy x y2, etc...]? If not, what is 'add x y' creates?
4. How to print the result of 'add x y'?

Also, I understand the following
"instance (Ord a) => Monad a where ...."

as type of the 'a' must be an extension of type Ord.
How shall I understand code below?
  "instance (Add Integer a) => Add Integer [a]"

Thanks a lot.


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

Message: 6
Date: Tue, 2 Jun 2009 16:47:25 -0400
From: Brent Yorgey <byor...@seas.upenn.edu>
Subject: Re: [Haskell-beginners] Type Class question
To: beginners@haskell.org
Message-ID: <20090602204725.ga19...@seas.upenn.edu>
Content-Type: text/plain; charset=us-ascii

On Tue, Jun 02, 2009 at 03:44:48PM -0400, Malik H wrote:
> I am reading article "Fun with type functions" and I have a few
> questions regarding examples presented in it. Here is the code
> 
> class Add a b where
>     type SumTy a b
>     add :: a -> b -> SumTy a b
> 
> instance (Add Integer a) => Add Integer [a] where
>     type SumTy Integer [a] = [SumTy Integer a]
>     add x y = map (add x) y
> 
> Here are my questions:
> 1. Is type "SumTy Integer [a]" visible outside 'Add' instance?

Yes.

> 2. If yes, how would you create and instance of that type without
> using 'add' function?

Notice that the 'type' declaration just sets up an equality between
types.  So 'SumTy Integer [a]' is *the same as* [SumTy Integer a].
Now, what is 'SumTy Integer a'?  Well, it depends on what a is.  In
the paper they give an example when a = Double, then SumTy Integer
Double = Double.  So we see that

  SumTy Integer [Double] = [SumTy Integer Double] = [Double].

So, since 'SumTy Integer [Double]' is really just a fancy way of
saying [Double], you can create a value of that type in any way you
would normally create a value of type [Double].  For example,

  [3.0, 2.9, 6.6] :: SumTy Integer [Double]

> 3. Will function 'add x y' create the following structure [SumTy x y1,
> SumTy x y2, etc...]? If not, what is 'add x y' creates?

No, SumTy is a function on *types*, and x and y are *values*.  So
saying 'SumTy x y1' does not make sense.  Suppose

  x = 3 :: Integer
  y = [3.1, 2.9] :: [Double]

then

  add x y = [6.1, 5.9] :: SumTy Integer [Double]

> 4. How to print the result of 'add x y'?

It depends on the type of x and y; but from above I hope you can see
that there is nothing special about the values you get out of 'add';
the result of 'add' will just be a normal value whose type is
determined by the 'SumTy' type function.

> 
> Also, I understand the following
> "instance (Ord a) => Monad a where ...."
> 
> as type of the 'a' must be an extension of type Ord.
> How shall I understand code below?
>   "instance (Add Integer a) => Add Integer [a]"

This means that we can add an Integer to a list of a's, as long as we
know how to add an Integer to something of type a.


-Brent


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

Message: 7
Date: Tue, 2 Jun 2009 23:57:58 -0500
From: aditya siram <aditya.si...@gmail.com>
Subject: [Haskell-beginners] HaXML tutorial
To: beginners <beginners@haskell.org>
Message-ID:
        <594f78210906022157l3c0f9d8eq3d1241b5d1610...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hi all,
Are there any current HaXml 1.13.2 tutorials/examples out there? I found the
one from their webpage (
http://www.krowland.net/tutorials/haxml_tutorial.html) to be quite
confusing.

thanks ..
-deech
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20090603/17e2c50a/attachment-0001.html

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

Message: 8
Date: Wed, 3 Jun 2009 00:42:01 -0500
From: aditya siram <aditya.si...@gmail.com>
Subject: [Haskell-beginners] HXT runtime error
To: beginners <beginners@haskell.org>
Message-ID:
        <594f78210906022242m46281578x54b78cf0aa628...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Hi all,
I am trying to use HXT to parse an XML file. However whenever I try and run
'xread', GHCI crashes. The code and output are below.

The following code queries isbndb.com ( a book ISBN database ) which
responds with XML describing the book. I am using 'xread' from HXT to parse
the response into an XMLTree.

respHTML'' isbn = do
      rsp <- simpleHTTP (getRequest $ "
http://isbndb.com/api/books.xml?results=details&access_key=";
                                ++ key
                                ++ "&index1=isbn&value1="
                                ++ isbn :: Request_String)
      case rsp of
        Left x  -> putStrLn $ "Error " ++ (show x)
        Right r -> putStrLn $ show $ xread $ rspBody r

When I try this respHTML'' in GHCI usin the isbn for "Real World Haskell" ,
this is what I get:

*Main> respHTML'' rwhis
Loading package syb ... linking ... done.
Loading package base-3.0.3.1 ... linking ... done.
Loading package array-0.2.0.0 ... linking ... done.
Loading package containers-0.2.0.1 ... linking ... done.
Loading package bytestring-0.9.1.4 ... linking ... done.
Loading package old-locale-1.0.0.1 ... linking ... done.
Loading package old-time-1.0.0.2 ... linking ... done.
Loading package unix-2.3.2.0 ... linking ... done.
Loading package filepath-1.1.0.2 ... linking ... done.
Loading package directory-1.0.0.3 ... linking ... done.
Loading package process-1.0.1.1 ... linking ... done.
Loading package pretty-1.0.1.0 ... linking ... done.
Loading package random-1.0.0.1 ... linking ... done.
Loading package haskell98 ... linking ... done.
Loading package parsec-2.1.0.1 ... linking ... done.
Loading package network-2.2.1 ... linking ... done.
Loading package mtl-1.1.0.2 ... linking ... done.
Loading package parallel-1.1.0.1 ... linking ... done.
Loading package HTTP-4000.0.6 ... linking ... done.
Loading package HaXml-1.13.3 ... linking ... done.
Loading package MaybeT-0.1.2 ... linking ... done.
Loading package HUnit-1.2.0.3 ... linking ... done.
Loading package curl-1.3.5 ... linking ... done.
Loading package network-2.2.1.2 ...

GHCi runtime linker: fatal error: I found a duplicate definition for symbol
   my_inet_ntoa
whilst processing object file
   /home/deech/.cabal/lib/network-2.2.1.2/ghc-6.10.3/HSnetwork-2.2.1.2.o
This could be caused by:
   * Loading two different object files which export the same symbol
   * Specifying the same object file twice on the GHCi command line
   * An incorrect `package.conf' entry, causing some object to be
     loaded twice.
GHCi cannot safely continue in this situation.  Exiting now.  Sorry.

It seems to want to load the 'network' package twice. Is this causing the
trouble?

thanks ,
deech
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20090603/c5344a6a/attachment-0001.html

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

Message: 9
Date: Wed, 3 Jun 2009 00:52:38 -0500
From: aditya siram <aditya.si...@gmail.com>
Subject: [Haskell-beginners] Re: HXT runtime error
To: beginners <beginners@haskell.org>
Message-ID:
        <594f78210906022252m215d292fr9e611ca5bed8e...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Upon further investigation, it seems my problem is using HaXml 1.13.2 and
HXT 8.3.0 in the same file. Furthermore I can't even import both HaXml and
HXT because they each pull in different versions of 'network' which is
causing the 'duplicate definition for symbol' problem. I can't think of a
workaround - so I guess it's one or the other.

Also is there any reason the cabal installed version of HaXml 1.13.3 is so
far behind the latest release 1.19.7? Is HXT, with a far more recent
release, preferable overall?

thanks,
deech

On Wed, Jun 3, 2009 at 12:42 AM, aditya siram <aditya.si...@gmail.com>wrote:

> Hi all,
> I am trying to use HXT to parse an XML file. However whenever I try and run
> 'xread', GHCI crashes. The code and output are below.
>
> The following code queries isbndb.com ( a book ISBN database ) which
> responds with XML describing the book. I am using 'xread' from HXT to parse
> the response into an XMLTree.
>
> respHTML'' isbn = do
>       rsp <- simpleHTTP (getRequest $ "
> http://isbndb.com/api/books.xml?results=details&access_key=";
>                                 ++ key
>                                 ++ "&index1=isbn&value1="
>                                 ++ isbn :: Request_String)
>       case rsp of
>         Left x  -> putStrLn $ "Error " ++ (show x)
>         Right r -> putStrLn $ show $ xread $ rspBody r
>
> When I try this respHTML'' in GHCI usin the isbn for "Real World Haskell" ,
> this is what I get:
>
> *Main> respHTML'' rwhis
> Loading package syb ... linking ... done.
> Loading package base-3.0.3.1 ... linking ... done.
> Loading package array-0.2.0.0 ... linking ... done.
> Loading package containers-0.2.0.1 ... linking ... done.
> Loading package bytestring-0.9.1.4 ... linking ... done.
> Loading package old-locale-1.0.0.1 ... linking ... done.
> Loading package old-time-1.0.0.2 ... linking ... done.
> Loading package unix-2.3.2.0 ... linking ... done.
> Loading package filepath-1.1.0.2 ... linking ... done.
> Loading package directory-1.0.0.3 ... linking ... done.
> Loading package process-1.0.1.1 ... linking ... done.
> Loading package pretty-1.0.1.0 ... linking ... done.
> Loading package random-1.0.0.1 ... linking ... done.
> Loading package haskell98 ... linking ... done.
> Loading package parsec-2.1.0.1 ... linking ... done.
> Loading package network-2.2.1 ... linking ... done.
> Loading package mtl-1.1.0.2 ... linking ... done.
> Loading package parallel-1.1.0.1 ... linking ... done.
> Loading package HTTP-4000.0.6 ... linking ... done.
> Loading package HaXml-1.13.3 ... linking ... done.
> Loading package MaybeT-0.1.2 ... linking ... done.
> Loading package HUnit-1.2.0.3 ... linking ... done.
> Loading package curl-1.3.5 ... linking ... done.
> Loading package network-2.2.1.2 ...
>
> GHCi runtime linker: fatal error: I found a duplicate definition for symbol
>    my_inet_ntoa
> whilst processing object file
>    /home/deech/.cabal/lib/network-2.2.1.2/ghc-6.10.3/HSnetwork-2.2.1.2.o
> This could be caused by:
>    * Loading two different object files which export the same symbol
>    * Specifying the same object file twice on the GHCi command line
>    * An incorrect `package.conf' entry, causing some object to be
>      loaded twice.
> GHCi cannot safely continue in this situation.  Exiting now.  Sorry.
>
> It seems to want to load the 'network' package twice. Is this causing the
> trouble?
>
> thanks ,
> deech
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
http://www.haskell.org/pipermail/beginners/attachments/20090603/3e26b909/attachment.html

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

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 12, Issue 2
****************************************

Reply via email to