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:  numerical integration over lists (Thomas Engel)
   2. Re:  numerical integration over lists (Thomas Engel)
   3.  First program (ARJANEN Lo?c Jean David)
   4. Re:  numerical integration over lists (Daniel Fischer)
   5. Re:  numerical integration over lists (Thomas Engel)
   6. Re:  First program (Erlend Hamberg)
   7.  Newtype to avoid orphans (Adrien Haxaire)
   8. Re:  First program (edgar klerks)


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

Message: 1
Date: Sun, 5 Feb 2012 17:32:44 +0100
From: Thomas Engel <[email protected]>
Subject: Re: [Haskell-beginners] numerical integration over lists
To: Benjamin Edwards <[email protected]>
Cc: [email protected]
Message-ID: <20120205163243.GA3280@siduxbox>
Content-Type: text/plain; charset=us-ascii

Hello Benjamin,

> 
>    [Float] is a list of floats. (Float) is not.
thanks for pointing out an error. But now I get an other error message.

integriereListe::[Float]->[Float]->[Float]
integriereListe [][]  = 0.0
integriereListe (x:xs) (y:ys)   = (y - y2) / 2.0 * (x2 -x)
                                 where
                                 x2 = head xs
                                 y2 = head ys

No instance for (Fractional [Float])
      arising from a use of `/'
    Possible fix: add an instance declaration for (Fractional [Float])
    In the first argument of `(*)', namely `(y - y2) / 2.0'
    In the expression: (y - y2) / 2.0 * (x2 - x)
    In an equation for `integriereListe':
        integriereListe (x : xs) (y : ys)
          = (y - y2) / 2.0 * (x2 - x)
          where
              x2 = head xs
              y2 = head ys

Thomas



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

Message: 2
Date: Sun, 5 Feb 2012 18:18:54 +0100
From: Thomas Engel <[email protected]>
Subject: Re: [Haskell-beginners] numerical integration over lists
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID: <20120205171853.GA3663@siduxbox>
Content-Type: text/plain; charset=us-ascii

Hello Daniel,

thank you very much for pointing out a solution.  
> If I understand correctly, use
> 
> zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
> 
> -- calculates the list of differences between successive elements,
> -- differences [x1,x2,x3,...] = [x2-x1, x3-x2, ...]
> --
> -- We use subtract and don't swap the list arguments to zipWith
> -- becuase this way there is no need to handle an empty list
> -- specially, zipWith's definition lets (tail xs) unevaluated in that case.
> --
> differences :: Num a => [a] -> [a]
> differences xs = zipWith subtract xs (tail xs)
> 
> areas :: Floating a => [a] -> [a] -> [a]
> areas xs ys
>     = zipWith (\dx dy -> dx * dy/2) (differences xs) (differences ys)
> 
> -- if it should have been (y+y2)/2 above, make that
Yes, you are right. That should be an sum instead of a difference.

> -- sums ys, where sums ks = zipWith (+) ks
> -- or areas xs ys = zipWith (*) (differenses xs) (means ys)
> -- where means zs = map (/ 2) (sums zs)

I have changed the functions according your advice. But still I get an error:

differences :: Num a => [a] -> [a]
differences xs = zipWith subtract xs (tail xs)

areas :: Floating a => [a] -> [a] -> [a]
areas xs ys
    = zipWith (*) (differences xs) (means ys)
      where means zs = map (/ 2) (sums zs)
                       where sums ks = zipWith (+) ks

integrals xs ys = scanl (+) 0 (areas xs ys)

Couldn't match expected type `[b0]' with actual type `[c0] -> [c0]'
In the return type of a call of `sums'
In the second argument of `map', namely `(sums zs)'
In the expression: map (/ 2) (sums zs)

Thomas




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

Message: 3
Date: Sun, 05 Feb 2012 18:38:28 +0100
From: ARJANEN Lo?c Jean David <[email protected]>
Subject: [Haskell-beginners] First program
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hello,

I am learning Haskell, and as a first program have made a JSON-RPC 
client library (code accessible here: 
https://patch-tag.com/r/Azel/hs-json-rpc/home). I would like to know if 
I have done great errors, be that errors of style or of library use.
Thanking you for your time.

Best regards,
ARJANEN Lo?c



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

Message: 4
Date: Sun, 5 Feb 2012 19:09:22 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] numerical integration over lists
To: Thomas Engel <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain;  charset="iso-8859-1"

On Sunday 05 February 2012, 18:18:54, Thomas Engel wrote:
> 
> > -- sums ys, where sums ks = zipWith (+) ks

Sigh, that's what you get for hopping to and fro while writing a mail.
That should have been

sums ks = zipWith (+) ks (tail ks)

like for differences

> > -- or areas xs ys = zipWith (*) (differenses xs) (means ys)
> > -- where means zs = map (/ 2) (sums zs)
> 
> I have changed the functions according your advice. But still I get an
> error:
> 
> differences :: Num a => [a] -> [a]
> differences xs = zipWith subtract xs (tail xs)
> 
> areas :: Floating a => [a] -> [a] -> [a]
> areas xs ys
>     = zipWith (*) (differences xs) (means ys)
>       where means zs = map (/ 2) (sums zs)
>                        where sums ks = zipWith (+) ks

It wasn't meant to be understood so, I intended differences etc. to be top-
level functions, that's more readable.




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

Message: 5
Date: Sun, 5 Feb 2012 20:14:42 +0100
From: Thomas Engel <[email protected]>
Subject: Re: [Haskell-beginners] numerical integration over lists
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID: <20120205191442.GA3878@siduxbox>
Content-Type: text/plain; charset=us-ascii

Hello Daniel,

* Daniel Fischer <[email protected]> [120205 19:17]:
> On Sunday 05 February 2012, 18:18:54, Thomas Engel wrote:
> > 
> > > -- sums ys, where sums ks = zipWith (+) ks
> 
> Sigh, that's what you get for hopping to and fro while writing a mail.
> That should have been
> 
> sums ks = zipWith (+) ks (tail ks)
it's working now
> 
> 
> It wasn't meant to be understood so, I intended differences etc. to be top-
> level functions, that's more readable.
> 
I have made an additional function for sums

Thanks again

Thomas



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

Message: 6
Date: Mon, 6 Feb 2012 10:19:43 +0100
From: Erlend Hamberg <[email protected]>
Subject: Re: [Haskell-beginners] First program
To: ARJANEN Lo?c Jean David <[email protected]>
Cc: [email protected]
Message-ID:
        <CA+G9OX=xjFX-NNJ8i64oAySo-ACWk=tnbm6bkt2k7ocoksq...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Hi,

On 5 February 2012 18:38, ARJANEN Lo?c Jean David
<[email protected]> wrote:
> I would like to know if I have done great errors, be that errors of style or 
> of library use.

A good start is to use the hlint program [1] on your source code and
evaluate its suggestions.

[1] http://community.haskell.org/~ndm/hlint/

-- 
Erlend Hamberg
[email protected]



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

Message: 7
Date: Mon, 06 Feb 2012 10:31:50 +0100
From: Adrien Haxaire <[email protected]>
Subject: [Haskell-beginners] Newtype to avoid orphans
To: <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed

 Hello,

 In the library I am writing, I declare a type Vector for Data.Vector 
 Double. I then create a Num instance for it as it doesn't have one yet. 
 GHC tells me that this instance is an orphan. After reading several 
 answers to issues like mine, I want to get rid of these orphans. The 
 advice I saw mostly is to use the newtype keyword.

 Is there a way to do it nicely, instead of copying most of the API of 
 Data.Vector ?

 Now, the only thing I can see is do like in this example:

 import Data.Vector as V

 newtype VectorD = VectorD (V.Vector Double)

 map :: (Double -> Double) -> VectorD -> VectorD
 map f (VectorD v) = VectorD $ V.map f v


 Is there a better way ?

 Best regards,
 Adrien




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

Message: 8
Date: Mon, 6 Feb 2012 10:38:49 +0100
From: edgar klerks <[email protected]>
Subject: Re: [Haskell-beginners] First program
To: Erlend Hamberg <[email protected]>
Cc: [email protected], ARJANEN Lo?c Jean David
        <[email protected]>
Message-ID:
        <cagauytkowm_4dq-aoej1br1lz+-1dqzo1aqbddxrbbt5fgb...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1

Your code look very nice.

One suggestion I could make is to use an error monad for the error
handling. This will take a lot of work from your hands in a later
stage in the development of your project.

On 2/6/12, Erlend Hamberg <[email protected]> wrote:
> Hi,
>
> On 5 February 2012 18:38, ARJANEN Lo?c Jean David
> <[email protected]> wrote:
>> I would like to know if I have done great errors, be that errors of style
>> or of library use.
>
> A good start is to use the hlint program [1] on your source code and
> evaluate its suggestions.
>
> [1] http://community.haskell.org/~ndm/hlint/
>
> --
> Erlend Hamberg
> [email protected]
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



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

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


End of Beginners Digest, Vol 44, Issue 8
****************************************

Reply via email to