Re: [Haskell-cafe] Mathematics and Statistics libraries

2012-03-25 Thread Heinrich Apfelmus

Tom Doris wrote:


If you're interested in UI work, ideally we'd have something similar
to RStudio as an environment, a simple set of windows encapsulating an
editor, a repl, a plotting panel and help/history, this sounds
superficial but it really has an impact when you're exploring a data
set and trying stuff out.


Concerning UI, the following project suggestion aims to give GHCi a web GUI

  http://hackage.haskell.org/trac/summer-of-code/ticket/1609

But one of your criteria is that a good UI should come with a help 
system, too, right?



Best regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com


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


Re: [Haskell-cafe] Open-source projects for beginning Haskell students?

2012-03-25 Thread Heinrich Apfelmus

John Lato wrote:

From: Heinrich Apfelmus

Also, as far as I am aware, you can't do low-level audio programming in
SuperCollider, i.e. play a list of samples that you've calculated
yourself. That's cool if you're only interested in sound design, but bad
for learning how audio programming works.


I think this charge is a bit unfair.  If you really want to do
low-level stuff, it's possible within SC.  You just have to work in
SuperCollider, not Haskell (AFAIK).


Ah, right, I meant from within Haskell, i.e. by communicating with the 
SC3 server component. Even in SC you have to write unit generators in C, 
I think, but I may well be mistaken.



However, it is possible to transfer audio data between Haskell and
Csound, in several ways.  The hCsound package comes with some examples
of transferring the audio input and output streams between csound and
haskell.  Named channels provide for even more complicated routing if
you like.


I didn't know about the hCsound package, that might have saved me some work.


Best regards,
Heinrich Apfelmus

--
http://apfelmus.nfshost.com


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


[Haskell-cafe] Using HaXml

2012-03-25 Thread Yves Parès
Hello café,

Provided what I read, HaXml seems to be the recommended library for parsing
XML files (I'm trying to browse and alter spreadsheets (ODS) and possibly
release a package when I'm done), is there somewhere tutorials on how to
use it?
I used 'xml' package by the past, but HaXml is more substantial.

Thanks.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Using HaXml

2012-03-25 Thread aditya bhargava
I don't know much about HaXml, but HXT is based on it and comes with a
tutorial:

http://www.haskell.org/haskellwiki/HXT

I also show some basic functionality of HXT in this blog post:

http://adit.io/posts/2012-03-10-building_a_concurrent_web_scraper_with_haskell.html

I'm curious to hear how HaXml compares to HXT / HXML / TagSoup.


Adit



On Sun, Mar 25, 2012 at 1:34 AM, Yves Parès yves.pa...@gmail.com wrote:

 Hello café,

 Provided what I read, HaXml seems to be the recommended library for
 parsing XML files (I'm trying to browse and alter spreadsheets (ODS) and
 possibly release a package when I'm done), is there somewhere tutorials on
 how to use it?
 I used 'xml' package by the past, but HaXml is more substantial.

 Thanks.

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




-- 
adit.io
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Mathematics and Statistics libraries

2012-03-25 Thread Tom Doris
Hi Heinrich,

If we compare the GHCi experience with R or IPython, leaving aside any
GUIs, the help system they have at the repl level is just a lot more
intuitive and easy to use, and you get access to the full manual
entries. For example, compare what you see if you type :info sort into
GHCi versus ?sort in R. R gives you a view of the full docs for the
function, whereas in GHCi you just get the type signature.

I usually def a command to call out to :!hoogle --info %, which
gives what you expect :info should. So, as is usually the case,
there's a solution in Haskell that matches the features in other
systems, but it's not the default and you have to invest effort
getting it set up right. This is fine for Haskell devs who do some
stats work, but it represents an offputtingly steep learning curve for
quants who are willing to learn a little Haskell but expect
(reasonably) some basic stuff like inline help to Just Work.

Tom

On 25 March 2012 08:26, Heinrich Apfelmus apfel...@quantentunnel.de wrote:
 Tom Doris wrote:


 If you're interested in UI work, ideally we'd have something similar
 to RStudio as an environment, a simple set of windows encapsulating an
 editor, a repl, a plotting panel and help/history, this sounds
 superficial but it really has an impact when you're exploring a data
 set and trying stuff out.


 Concerning UI, the following project suggestion aims to give GHCi a web GUI

  http://hackage.haskell.org/trac/summer-of-code/ticket/1609

 But one of your criteria is that a good UI should come with a help system,
 too, right?


 Best regards,
 Heinrich Apfelmus

 --
 http://apfelmus.nfshost.com



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

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


[Haskell-cafe] adding the elements of two lists

2012-03-25 Thread TP
Hello,

My primary problem may be reduced to adding elements of two lists:
[1,2,3] + [4,5,6] = [5,7,9]

My first idea was to declare a list of Int as an instance of Num, and define 
(+) 
in the correct way.
However, it seems it is not possible to do that:

---
instance Num [Int] where
l1 + l2 = 
---

Why?
It seems it is necessary to do:

--
newtype ListOfInt = ListOfInt { getList :: [Int] }
deriving (Show, Eq)

instance Num ListOfInt where
 l1 + l2 = ...
---

Am I correct? Is it the best way to do that?

Now, what is the most usual way to implement l1+l2?
I have just read about applicative functors, with which I can do:

---
import Control.Applicative
let l1 = [1,2,3]
let l2 = [4,5,6]
print $ getZipList $ (+) $ ZipList l1 * ZipList l2
[5,7,9]
---

Is it the correct way to do that?
I have tried:

---
instance Num ListOfInt where
 l1 + l2 = ListOfInt $ getZipList $ (+) $ ZipList (getList l1) *
 ZipList (getList l2)
---

Isn't it too much complicated?

Thanks

TP

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


Re: [Haskell-cafe] adding the elements of two lists

2012-03-25 Thread Michael Snoyman
On Sun, Mar 25, 2012 at 2:01 PM, TP paratribulati...@free.fr wrote:
 Hello,

 My primary problem may be reduced to adding elements of two lists:
 [1,2,3] + [4,5,6] = [5,7,9]

 My first idea was to declare a list of Int as an instance of Num, and define 
 (+)
 in the correct way.
 However, it seems it is not possible to do that:

 ---
 instance Num [Int] where
        l1 + l2 = 
 ---

 Why?
 It seems it is necessary to do:

 --
 newtype ListOfInt = ListOfInt { getList :: [Int] }
    deriving (Show, Eq)

 instance Num ListOfInt where
     l1 + l2 = ...
 ---

 Am I correct? Is it the best way to do that?

 Now, what is the most usual way to implement l1+l2?
 I have just read about applicative functors, with which I can do:

 ---
 import Control.Applicative
 let l1 = [1,2,3]
 let l2 = [4,5,6]
 print $ getZipList $ (+) $ ZipList l1 * ZipList l2
 [5,7,9]
 ---

 Is it the correct way to do that?
 I have tried:

 ---
 instance Num ListOfInt where
     l1 + l2 = ListOfInt $ getZipList $ (+) $ ZipList (getList l1) *
                                     ZipList (getList l2)
 ---

 Isn't it too much complicated?

 Thanks

 TP

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

A simple solution is to use the zipWith[1] function:

zipWith (+) [1,2,3] [4,5,6] == [5,7,9]

It takes a bit of time to get acquainted with all of the incredibly
convenient functions in base, but once you know them, it can greatly
simplify your code.

Michael

[1] 
http://hackage.haskell.org/packages/archive/base/4.5.0.0/doc/html/Prelude.html#v:zipWith

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


Re: [Haskell-cafe] adding the elements of two lists

2012-03-25 Thread Jonathan Grochowski
On Sun, Mar 25, 2012 at 5:01 AM, TP paratribulati...@free.fr wrote:

 Hello,

 My primary problem may be reduced to adding elements of two lists:
 [1,2,3] + [4,5,6] = [5,7,9]

 My first idea was to declare a list of Int as an instance of Num, and
 define (+)
 in the correct way.
 However, it seems it is not possible to do that:

 ---
 instance Num [Int] where
l1 + l2 = 
 ---

 Why?
 It seems it is necessary to do:

 --
 newtype ListOfInt = ListOfInt { getList :: [Int] }
deriving (Show, Eq)

 instance Num ListOfInt where
 l1 + l2 = ...
 ---

 Am I correct? Is it the best way to do that?

 Now, what is the most usual way to implement l1+l2?
 I have just read about applicative functors, with which I can do:

 ---
 import Control.Applicative
 let l1 = [1,2,3]
 let l2 = [4,5,6]
 print $ getZipList $ (+) $ ZipList l1 * ZipList l2
 [5,7,9]
 ---

 Is it the correct way to do that?
 I have tried:

 ---
 instance Num ListOfInt where
 l1 + l2 = ListOfInt $ getZipList $ (+) $ ZipList (getList l1) *
 ZipList (getList l2)
 ---

 Isn't it too much complicated?

 Thanks

 TP

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


As Michael suggests using zipWith (+) is the simplest solution.

If you really want to be able to write [1,2,3] + [4,5,6], you can define
the instnace as

instance (Num a) = Num [a] where
xs + ys = zipWith (+) xs ys

You'll also likely want to give definitions for the other functions ((*),
abs, signum, etc.) as well.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] adding the elements of two lists

2012-03-25 Thread Jerzy Karczmarczuk

TP  :

However, it seems it is not possible to do that:

---
instance Num [Int] where
l1 + l2 = 
---

Why?

Why not?? It is possible.

All what has been said by other people is right.
But you can do it your way as well, GHC won't protest if you :set 
-XFlexibleInstances .


(Then you might have some other small problems, but nobody is perfect).


Jerzy Karczmarczuk


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


Re: [Haskell-cafe] Mathematics and Statistics libraries

2012-03-25 Thread Aleksey Khudyakov

On 25.03.2012 14:52, Tom Doris wrote:

Hi Heinrich,

If we compare the GHCi experience with R or IPython, leaving aside any
GUIs, the help system they have at the repl level is just a lot more
intuitive and easy to use, and you get access to the full manual
entries. For example, compare what you see if you type :info sort into
GHCi versus ?sort in R. R gives you a view of the full docs for the
function, whereas in GHCi you just get the type signature.

Ingrating haddock documentation into GHCi would be really helpful but 
it's GSoC project on its own.


For me most important difference between R's repl and GHCi is that 
:reload wipes all local binding. Effectively it forces to write 
everything in file and to avoid doing anything which couldn't be fitted 
into one-liner. It may not be bad but it's definitely different style


And of course data visualization. Only library I know of is Chart[1] but 
I don't like API much.


I think talking about data frames is a bit pointless unless we specify 
what is data frame. Basically there are two representations of tabular 
data structure: array of tuples or tuple of arrays. If you want first go 
for Data.Vector.Vector YourData. If you want second you'll probably end 
up with some HList-like data structure to hold arrays.




[1] http://hackage.haskell.org/package/Chart

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


[Haskell-cafe] GSoC project ideas for web technology

2012-03-25 Thread Jeremy Shaw
Hello,

If you are looking for some ideas for a GSoC project, I have written down
some web technology related projects I would like to see.

So far I mostly have ideas for improvements to HSX (a templating solution)
and acid-state (a pure, haskell persistent datastore). Both these
technologies can be used with any Haskell web framework (though they are
embraced most fully by Happstack).

http://code.google.com/p/happstack/wiki/GoogleSummerOfCode

I am an officially registered Haskell GSoC mentor. I am happy to help
expand any of these ideas into a genuine GSoC proposal and to act as a
mentor on the project. If you have other ideas you wish to pitch, I am
happy to hear those as well.

- jeremy
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] How to handle C library dependencies on Hackage?

2012-03-25 Thread .
Hello Cafe,
I recently did my first upload to Hackage:
http://hackage.haskell.org/package/jalla.
The library does not build (and therefore unfortunately the
documentation is not built either), because
the C library that it needs to wrap is usually not installed with normal
Linux distributions. It's LAPACKE (note the E at the end).
I /could/ upload the source code of that library alongside my Haskell
library and build it using Setup.hs (this works on my computer).
However, LAPACKE is large compated to my own library (about 16MB
sources) and I don't want to flood Hackage with it if it's not
necessary.

Can anyone here give me some advice on how to solve this on the system
that builds the hackage packages?

Thanks very much,
Christian



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


Re: [Haskell-cafe] Open-source projects for beginning Haskell students?

2012-03-25 Thread Stefan Kersten
On 25.03.12 09:38, Heinrich Apfelmus wrote:
 John Lato wrote:
 From: Heinrich Apfelmus

 Also, as far as I am aware, you can't do low-level audio programming in
 SuperCollider, i.e. play a list of samples that you've calculated
 yourself. That's cool if you're only interested in sound design, but bad
 for learning how audio programming works.

 I think this charge is a bit unfair.  If you really want to do
 low-level stuff, it's possible within SC.  You just have to work in
 SuperCollider, not Haskell (AFAIK).
 
 Ah, right, I meant from within Haskell, i.e. by communicating with the SC3
 server component. Even in SC you have to write unit generators in C, I think,
 but I may well be mistaken.

there's a more functional option, too: faust [1] ;)

sk

[1] http://faust.grame.fr/index.php/documentation/what-faust

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


Re: [Haskell-cafe] How to handle C library dependencies on Hackage?

2012-03-25 Thread Stephen Tetley
Hi Christian

Usually people host the documentation on their own site and put a link
in the description field of the cabal file, pointing users to it.

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


Re: [Haskell-cafe] adding the elements of two lists

2012-03-25 Thread Richard O'Keefe

On 26/03/2012, at 1:01 AM, TP wrote:

 Hello,
 
 My primary problem may be reduced to adding elements of two lists:
 [1,2,3] + [4,5,6] = [5,7,9]

zipWith (+) [1,2,3] [4,5,6]
gets the job done.
 
 However, it seems it is not possible to do that:
 
 ---
 instance Num [Int] where
   l1 + l2 = 
 ---
 
 Why?

Because the 'instance' machinery is keyed off the *outermost* type
constructor (here []) not the *whole* type (here [Int]) and the
reason for that is polymorphism; we want to be able to work with
[t] where t is not specially constrained.

You *can* do
instance (Num t) = Num [t] where ...

 It seems it is necessary to do:
 
 --
 newtype ListOfInt = ListOfInt { getList :: [Int] }

That's *still* a good idea because there are lots of different
things that arithmetic on lists might mean.  For example,
is [1,2] + [3,4,5] an error or not?  If it is not an error,
what actually happens?


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


Re: [Haskell-cafe] adding the elements of two lists

2012-03-25 Thread Chris Smith
Jonathan Grochowski jongrocho...@gmail.com wrote:
 As Michael suggests using zipWith (+) is the simplest solution.

 If you really want to be able to write [1,2,3] + [4,5,6], you can define
the instnace as

 instance (Num a) = Num [a] where
 xs + ys = zipWith (+) xs ys

You can do this in the sense that it's legal Haskell... but it is a bad
idea to make lists an instance of Num, because there are situations where
the result doesn't act as you would like (if you've had abstract algebra,
the problem is that it isn't a ring).

More concretely, it's not hard to see that the additive identity is
[0,0,0...], the infinite list of zeros.  But if you have a finite list x,
then x - x is NOT equal to that additive identity!  Instead, you'd only get
a finite list of zeros, and if you try to do math with that later, you're
going to accidentally truncate some answers now and then and wonder what
went wrong.

In general, most type classes in Haskell are like this... the compiler only
cares that you provide operations with certain types, but the type class
also carries around additional laws that you should obey when writing
instances.  Here there's no good way to write an instance that obeys the
laws, so it's better to write no instance at all.

-- 
Chris Smith
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] adding the elements of two lists

2012-03-25 Thread Jerzy Karczmarczuk

Le 26/03/2012 01:51, Chris Smith a écrit :


 instance (Num a) = Num [a] where
 xs + ys = zipWith (+) xs ys

You can do this in the sense that it's legal Haskell... but it is a 
bad idea to make lists an instance of Num, because there are 
situations where the result doesn't act as you would like (if you've 
had abstract algebra, the problem is that it isn't a ring).


More concretely, it's not hard to see that the additive identity is 
[0,0,0...], the infinite list of zeros.  But if you have a finite list 
x, then x - x is NOT equal to that additive identity!  Instead, you'd 
only get a finite list of zeros, and if you try to do math with that 
later, you're going to accidentally truncate some answers now and then 
and wonder what went wrong.


In general, most type classes in Haskell are like this... the compiler 
only cares that you provide operations with certain types, but the 
type class also carries around additional laws that you should obey 
when writing instances.  Here there's no good way to write an instance 
that obeys the laws, so it's better to write no instance at all.



Sorry, Chris, I disagree quite strongly.
You begin badly: the problem is that it isn't a ring.
Who told you so?

It MIGHT be a ring or not. The real problem is that one should not 
confuse structural and algebraic (in the classical sense) properties 
of your objects.


1. You may consider your lists as representants of polonomials. A very 
decent ring.


2. I used hundred times lists as representants of power series. 
Infinite, potentially, but often having just finite number of non-zero 
coefficients, and if those could be divided, the list was not only a 
ring, but a field. (Doug McIlroy did that as well, and his papers on 
power series are much better known than mine...) And NO, no truncation 
problems, if you know how to program correctly. The laziness helps.


3. A very similar stuff to series or polynomials is the usage of lists 
as differential algebras (uni-variate). I needed not only the numerical 
instances, but a derivation operator. A ring, a field, *different* from 
the previous ones.


4. I wanted to have the trajectories - the numerical sequences which 
were solutions of differential equations, to behave as mathematical 
objects that could be added, scaled, etc. A vector space, and much more.


5. I used lists as signals which could be added (sound composition), 
multiplied (modulation), etc. Good rings. Totally different from the 
previous ones.


Whether it would be better to use some specific ADT rather than lists, 
is a question of style. The fact that - as you say - there's no good 
way to write an instance that obeys the laws won't disturb my sleep. 
You know, there is no good way to organise a society where everybody 
obeys the Law. This is no argument against the organisation of a Society...


Thank you.

Jerzy Karczmarczuk



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


Re: [Haskell-cafe] adding the elements of two lists

2012-03-25 Thread Chris Smith
Jerzy Karczmarczuk jerzy.karczmarc...@unicaen.fr wrote:
 Le 26/03/2012 01:51, Chris Smith a écrit :

     instance (Num a) = Num [a] where
     xs + ys = zipWith (+) xs ys

 You can do this in the sense that it's legal Haskell... but it is a bad idea 
 [...]

 It MIGHT be a ring or not. The real problem is that one should not confuse
 structural and algebraic (in the classical sense) properties of your
 objects.

Of course there are rings for which it's possible to represent the
elements as lists.  Nevertheless, there is definitely not one that
defines (+) = zipWith (+), as did the one I was responding to.  By the
time you get a ring structure back by some *other* set of rules,
particularly for multiplication, the result will so clearly not be
anything like a general Num instance for lists that it's silly to even
be having this discussion.

-- 
Chris Smith

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


[Haskell-cafe] Google Summer of Code: a NUMA wishlist!

2012-03-25 Thread Sajith T S
Dear Cafe,

It's last minute-ish to bring this up (in my part of the world it's
still March 25), but graduate students are famously a busy and lazy
lot. :)  I study at Indiana University Bloomington, and I wish to
propose^W rush in this proposal and solicit feedback, mentors, etc
while I can.

Since student application deadline is April 6, I figure we can beat
this into a real proposal's shape by then.  This probably also falls
on the naive and ambitious side of things, and I might not even know
what I'm talking about, but let's see!  That's the idea of proposal,
yes?

Broadly, idea is to improve support for NUMA systems.  Specifically:

 -- Real physical processor affinity with forkOn [1].  Can we fire all
CPUs if we want to?  (Currently, the number passed to forkOn is
interpreted as number modulo the value returned by
getNumCapabilities [2]).

 -- Also kind of associated with the above: when launching processes,
we might want to specify a list of CPUs rather than the number of
CPUs.  Say, a -N [0,1,3] flag rather than -N 3 flag.  This shall
enable us to gawk at real pretty htop [3] output.
 
 -- From a very recent discussion on parallel-haskell [4], we learn
that RTS' NUMA support could be improved.  The hypothesis is that
allocating nurseries per Capability might be a better plan than
using global pool.  We might borrow/steal ideas from hwloc [5] for
this.

 -- Finally, a logging/monitoring infrastructure to verify assumptions
and determine if/how local work stays.

(I would like to acknowledge my fellow conspirators and leave them
unnamed, lest they shall be embarrassed by my... naivete.)

Thanks,
Sajith.

[1] 
http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent.html#v:forkOn
[2] 
http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent.html#v:getNumCapabilities
[3] http://htop.sourceforge.net/
[4] 
http://groups.google.com/group/parallel-haskell/browse_thread/thread/7ec1ebc73dde8bbd
[5] http://www.open-mpi.org/projects/hwloc/

-- 
the lyf so short, the craft so long to lerne.
 -- Chaucer.


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


Re: [Haskell-cafe] adding the elements of two lists

2012-03-25 Thread wren ng thornton

On 3/25/12 8:06 AM, Michael Snoyman wrote:

A simple solution is to use the zipWith[1] function:

 zipWith (+) [1,2,3] [4,5,6] == [5,7,9]

It takes a bit of time to get acquainted with all of the incredibly
convenient functions in base, but once you know them, it can greatly
simplify your code.

[1] 
http://hackage.haskell.org/packages/archive/base/4.5.0.0/doc/html/Prelude.html#v:zipWith


And if you want different behavior with regards to lists of differing 
length, you may also be interested in pairWith[2] or zipOrWith[3]


-- Silently truncate uneven lists.
zipWith (+) [1,2,3] [4,5,6] == [5,7,9]
zipWith (+) [1,2,3] [4,5]   == [5,7]

-- Give errors for uneven lists.
pairWith (+) [1,2,3] [4,5,6] == Just [5,7,9]
pairWith (+) [1,2,3] [4,5]   == Nothing

-- Assume infinitely many trailing zeros.
zipOrWith plus [1,2,3] [4,5,6] == [5,7,9]
zipOrWith plus [1,2,3] [4,5]   == [5,7,3]
where
plus (Fst x   ) = x
plus (Sndy) = y
plus (Both x y) = x+y


[2] 
http://hackage.haskell.org/packages/archive/list-extras/0.4.0.1/doc/html/Data-List-Extras-Pair.html#v:pairWith


[3] 
http://hackage.haskell.org/packages/archive/data-or/1.0.0/doc/html/Data-Or.html#v:zipOrWith


--
Live well,
~wren

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


Re: [Haskell-cafe] adding the elements of two lists

2012-03-25 Thread Richard O'Keefe

On 26/03/2012, at 12:51 PM, Chris Smith wrote:
 More concretely, it's not hard to see that the additive identity is 
 [0,0,0...], the infinite list of zeros.  But if you have a finite list x, 
 then x - x is NOT equal to that additive identity!

Said another way:  if you do want [num] to support + and -, then you DON'T
want the definitions of + and - to be unthinking applications of zipWith.

The approach I took the time I did this (before I learned better) was this:

smart_cons :: Num t = t - [t] - [t]
smart_cons 0 [] = []
smart_cons x xs = x : xs

instance Num t = Num [t]
  where  (x:xs) + (y:ys) = smart_cons (x+y) (xs + ys)
 xs + [] = xs
 [] + ys = ys
 ...
fromInteger 0 = []
fromInteger n = [n]
...

so that a finite list acted _as if_ it was followed by infinitely many zeros.
Of course this wasn't right either: if the inputs don't have trailing zeroes,
neither do the outputs, but if they _do_ have trailing zeros, [0]+[] = [0]
when it should = [].  That was about the time I realised this was a bad idea.



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


[Haskell-cafe] What happened with goa package repo?

2012-03-25 Thread Dmitry Malikov

Cloning into bare repository '/usr/portage/distfiles/egit-src/goa.git'...
fatal: The remote end hung up unexpectedly
 * ERROR: dev-haskell/goa- failed (unpack phase):
 *   git-2_initial_clone: can't fetch from 
git://github.com/chrisdone/goa.git


https://github.com/chrisdone/goa returns 404.

So it seems like Chris dropped that repo. Did someone have clone of it? 
It will be nice to put it back on github.


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