Re: [Haskell-cafe] What is the status of GPU-accelerated Haskell?

2011-10-28 Thread Rafael Gustavo da Cunha Pereira Pinto
Wow! That is cool!  I'll take a look...

Thanks folks!



On Fri, Oct 28, 2011 at 11:39, Ryan Newton rrnew...@gmail.com wrote:

 There are CUDA bindings:

http://hackage.haskell.org/package/cuda

 And that is what the higher-level GPU-programming package, Accelerate, is
 based on:

http://hackage.haskell.org/package/accelerate



 On Thu, Oct 27, 2011 at 4:04 PM, serialhex serial...@gmail.com wrote:

 Hi, there is an OpenCL / Haskell thread floating around the ML, mostly
 it's a dew ppl talking about merging the 5 (or so) bindings to the OpenCL
 api and getting spiffy multi-threaded haskell-awesomeness out of that.  i
 think they are discussing the benefits/drawbacks of a pure-ish api
 conversion or a more haskell-ish conversion, or some combination thereof.

 either way, it exsists, and it's happening (though i'm not so sure about
 CUDA bindings...  but OpenCL will work on Nvidia  ATI cards the same)

 hex



 On Thu, Oct 27, 2011 at 3:45 PM, Rafael Gustavo da Cunha Pereira Pinto 
 rafaelgcpp.li...@gmail.com wrote:



 Hi folks,

 I just bought a NVidia Fermi-based card and remembered reading a few
 months (years?) ago about some effort to accelerate array processing in
 Haskell using GPUs.

 How is this going on? Any progresses? Do we have GPU based DPH already?
 (the last one is a joke...)

 I keep thinking on the advantages of such GPU data processing on the
 signal processing field.

 Best regards,

 Rafael Gustavo da Cunha Pereira Pinto


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




 --
 *  my blog is cooler than yours: http://serialhex.github.com
 *  The wise man said: Never argue with an idiot. They bring you down to
 their level and beat you with experience.
 *  As a programmer, it is your job to put yourself out of business. What
 you do today can be automated tomorrow. ~Doug McIlroy
 ---
 CFO: “What happens if we train people and they leave?”
 CTO: “What if we don’t and they stay?”

 ___
 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




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] What is the status of GPU-accelerated Haskell?

2011-10-27 Thread Rafael Gustavo da Cunha Pereira Pinto
Hi folks,

I just bought a NVidia Fermi-based card and remembered reading a few months
(years?) ago about some effort to accelerate array processing in Haskell
using GPUs.

How is this going on? Any progresses? Do we have GPU based DPH already? (the
last one is a joke...)

I keep thinking on the advantages of such GPU data processing on the signal
processing field.

Best regards,

Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Building Haskell Platform natively for 64bit Windows

2011-06-09 Thread Rafael Gustavo da Cunha Pereira Pinto
It is 32 bits, I'm sure.

Besides the 32-bit stack manipulation, it uses eax and ecx to hold two
32-bit parts of the 64-bit number.

Best regards,

Rafael


On Thu, Jun 9, 2011 at 02:54, Scott Lawrence byt...@gmail.com wrote:

 On 06/09/2011 01:47 AM, Jason Dagit wrote:
  Have you checked this by looking at the generated assembly?  I
  generated some assembly from GHC on windows.  Here is what it looks
  ilke:
  http://hpaste.org/47610
 
  My assembly-fu is not strong enough to tell if it's using 64bit
 instructions.
 
 It would appear to be 32-bit. (pushl instead of pushq  no instances of
 aligning to 8-byte boundaries)


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




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Building Haskell Platform natively for 64bit Windows

2011-06-09 Thread Rafael Gustavo da Cunha Pereira Pinto
This really sucks.  Not even LLVM is ported to 64-bit Windows.

This is mainly because Windows uses 32-bit pointers for compatibility.
http://archive.gamedev.net/reference/programming/features/20issues64bit/

Atc

Rafael


On Thu, Jun 9, 2011 at 08:04, Rafael Gustavo da Cunha Pereira Pinto 
rafaelgcpp.li...@gmail.com wrote:

 It is 32 bits, I'm sure.

 Besides the 32-bit stack manipulation, it uses eax and ecx to hold two
 32-bit parts of the 64-bit number.

 Best regards,

 Rafael


 On Thu, Jun 9, 2011 at 02:54, Scott Lawrence byt...@gmail.com wrote:

 On 06/09/2011 01:47 AM, Jason Dagit wrote:
  Have you checked this by looking at the generated assembly?  I
  generated some assembly from GHC on windows.  Here is what it looks
  ilke:
  http://hpaste.org/47610
 
  My assembly-fu is not strong enough to tell if it's using 64bit
 instructions.
 
 It would appear to be 32-bit. (pushl instead of pushq  no instances of
 aligning to 8-byte boundaries)


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




 --
 Rafael Gustavo da Cunha Pereira Pinto




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] On hGetContents semi-closenesscloseness

2011-02-15 Thread Rafael Cunha de Almeida
From
http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-IO.html:

Computation hGetContents hdl returns the list of characters
corresponding to the unread portion of the channel or file
managed by hdl, which is put into an intermediate state,
semi-closed. In this state, hdl is effectively closed, but
items are read from hdl on demand and accumulated in a special
list returned by hGetContents hdl.

What state is that? It seems to be something related to Haskell. I
couldn't find a definition for it in the unix documentation I have
laying around.

Continuing reading System IO documentation I read:

Any operation that fails because a handle is closed, also fails
if a handle is semi-closed. The only exception is hClose. A
semi-closed handle becomes closed:

* if hClose is applied to it;
* if an I/O error occurs when reading an item from the
  handle;
* or once the entire contents of the handle has been read.

So it looks like hGetContents sets some flag in the handler saying it is in
that semi-closed state. So no other operations are valid, but I think the file
descriptor to the file is actually kept open. It's only when the contents are
entirely consumed that the descriptor gets closed. Is hGetContents responsible
for closing the descriptor? Or is it the garbage collector? Who closes the
descriptor when the contents are read? Looking at hGetContents function
definition, it uses lazyRead to read the contents, but it calls a
wantReadableHandle which might or might not close the handle after lazyRead.

By looking at the documentation it seems like the only way for us to actively
close the descriptor is either reading the whole thing or calling hClose. But
one has to be very carefully when to call the handler, because it doesn't
matter if it looks like it was consumed, it really has to be consumed.
The following code prints the contents of foo file to the screen:

openFile foo ReadMode = \handle - (hGetContents handle = (\s - putStr s 
 hClose handle)) [1]

The following code does not:

openFile foo ReadMode = \handle - (hGetContents handle = (\s - hClose 
handle  putStr s)) [2]

It is common knowledge that haskell is very lazy, so it only does things
when absolutely necessary, otherwise it prefers to write it off in the
TODO list.  It does that even if writing to the TODO takes longer than
the computation would, that's how lazy it is. That's the origin of the
often used expression he is quite a haskell.

The question most people doesn't have a good answer is: when does
Haskell thinks it is necessary to do something?

In [2] the lazyRead inside of hGetContents (or perhaps hGetContents all
together) only gets executed after hClose handle. Why is that? How do I
figure out the ordering of computation?


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


Re: [Haskell-cafe] Haskell, arrows and signal processing

2010-09-09 Thread Rafael Gustavo da Cunha Pereira Pinto
Just found it! It is pretty much what I was looking for,

On Thu, Sep 9, 2010 at 10:08, Wolfgang Jeltsch
g9ks1...@acme.softbase.orgwrote:

 Am Mittwoch, den 08.09.2010, 11:47 -0300 schrieb Rafael Gustavo da Cunha
 Pereira Pinto:
  The input and output are  infinite streams. I have a few questions:
 
  1) Is it possible to change it to use arrows? How would it look like?
  2) How would one implement an continuous time version?

 Have you had a look at Yampa?

 Best wishes,
 Wolfgang


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




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell, arrows and signal processing

2010-09-08 Thread Rafael Gustavo da Cunha Pereira Pinto
Hi folks from the cafe!!

Last weekend, I was wondering on how hard it would be to use Haskell for
mixed-signal processing.

Here is an example of an digital integrator:


summation=zipWith (+)

delay xs=(fromIntegral 0):xs

integrator xs=let ws=summation (integrator xs) xs in delay ws



The input and output are  infinite streams. I have a few questions:

1) Is it possible to change it to use arrows? How would it look like?
2) How would one implement an continuous time version?

For 2) I would like to implement something like that digital integrator, so
I could create filters based on integrator loops like this one:

x(t) (+) Integrator --|--- y(t)
  ^|
  ||


Note that x(t) would be a function, and I would expect to create a function
y, based on this flow!

Rafael Gustavo da Cunha Pereira Pinto




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Learning about Programming Languages (specifically Haskell)

2010-05-03 Thread Rafael Gustavo da Cunha Pereira Pinto
If you are running from GHCi, just type run 100 at the prompt..

If you intend to compile it, you have to add

main = print $ run 100

The compiler adds a call to main::IO (), which is intended to be the main
entry point of your code.

We need to add print, as run has type

run::Int-[Door]

so run 100 has type [Door].

print is

print::(Show a) = a - IO ()

The IO () stands for an empty IO monad, which is the black magic of haskell,
intended to separate pure code from I/O side-effects...




On Mon, May 3, 2010 at 06:31, Samuel Williams 
space.ship.travel...@gmail.com wrote:

 Also, one more thing - if someone could write some comments to go along
 with the source code that explain what it is doing, that would be really
 helpful. I can see the general structure, but I don't know the ins and outs
 of Haskell. If someone could augment the example with comments explaining
 what the functions do that would be great!

 data *Door* = *Open* | *Closed* deriving *Show*


 toggle *Open*   = *Closed*
 toggle *Closed* = *Open*


 pass k = zipWith ($) (cycle $ replicate k *id* ++ [toggle])


 run n = foldl (flip pass) (replicate n *Closed*) [0..n]

 Do I need to add run 100 to the end of the example for it to actually do
 something?

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




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell and the Software design process

2010-05-03 Thread Rafael Cunha de Almeida
Ivan Miljenovic ivan.miljeno...@gmail.com disse:
 On 3 May 2010 14:17, aditya siram aditya.si...@gmail.com wrote:
 I'm a little confused about this too. I've seen many functions defined like:
 f x = (\s - ...)
 which is a partial function because it returns a function and is the same as:
 f x s = ...

 No, that's a partially applied function.

 A partial function is one such as:

 secondElement (_:x:_) = x

 Note that it is only defined for lists with at least two elements, for
 any other list (i.e. singleton or empty) it will throw an error;
 -fwarn-incomplete-patterns (which is included in -Wall) tells you
 about these.

 You can also argue that functions such as head are partial, as they
 explicitly throw an error if the input data isn't correct.

 Partial functions are bad because if you accidentally use one the
 wrong way, your entire program crashes in a flaming wreck.  It's much
 better to do something like this:

 safeSecondElement (_:x:_) = Just x
 safeSecondElement _ = Nothing

 This will work with all possible input types.

I don't think that safeSecondElement is worse than secondElement. I think it's
better for the program to crash right away when you try to do something that
doesn't make sense.

Getting the secondElement of a list with one or less elements doesn't make
sense, so you are definetely doing something wrong if you expected the list to
have two elements, but it doesn't. It's best that the program crashes there,
than propagate the error and crash somewhere else or, worse, not crash at all
and give a wrong answer.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Haskellers hate GUIs!!

2010-04-02 Thread Rafael Cunha de Almeida
Stephen Tetley stephen.tet...@gmail.com disse:
 On 2 April 2010 17:53, Dominic Espinosa dces...@fastmail.fm wrote:

 [SNIP]

 I ended up rewriting it in another language (due to time
 pressure) and I'm a little wary of attempting to use Haskell again for
 developing such an application.

 Hi Dominic

 Out of curiosity what language did you choose instead?

 Each time a thread comes up on the Cafe documenting GUI woes, I always
 wonder if Python or other languages[*] have such problems and if not
 why not.

For better or worse python interpreter comes with Tk. So, if you develop your
application to use Tk, as ugly as it may look, it will work in every platform
supported by the python interpreter. However, if you want to use pygtk, you
still have to install gtk runtime.

When using haskell, can't you just make a static binary on MacOS and Windows,
though? Why wouldn't that work?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC vs GCC vs JHC

2010-03-27 Thread Rafael Cunha de Almeida
John Meacham wrote:
 Here are jhc's timings for the same programs on my machine. gcc and ghc
 both used -O3 and jhc had its full standard optimizations turned on.
 
 jhc:
 ./hs.out  5.12s user 0.07s system 96% cpu 5.380 total
 
 gcc:
 ./a.out  5.58s user 0.00s system 97% cpu 5.710 total
 
 ghc:
 ./try  31.11s user 0.00s system 96% cpu 32.200 total
 
 
 As you can see, jhc shines at this example, actually beating gcc -O3. It
 isn't too surprising, this is exactly the sort of haskell code that jhc
 excels at.

What's the property of that code which makes jhc excels in it? What
makes ghc perform so poorly in comparison?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC vs GCC vs JHC

2010-03-27 Thread Rafael Cunha de Almeida
Lennart Augustsson wrote:
 It's important to switch from mod to rem.  This can be done by a
 simple abstract interpretation.
 I'm nore sure if it's jhc or gcc that does this for jhc.
 

It's not just adding rem. Ghc still runs much slower using rem. It's
only when switching to -fvia-C and using rem that ghc gets close to gcc
speed (even though, still slower). Now jhc seems to get it fast right
away. What's going on here? Is ghc backend wrose than using gcc as a
backend (which is what via-C seems to accomplish)? Are there cases when
one way is preferred over the other? What are the tradeoffs here?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] GHC vs GCC

2010-03-26 Thread Rafael Cunha de Almeida
Hello,

During a talk with a friend I came up with two programs, one written in
C and another in haskell.

Haskell
main :: IO ()
main = print $ rangeI 0 0

rangeK :: Int - Int - Int - Int - Int
rangeK i j k acc
| k  1000 =
if i * i + j * j + k * k `mod` 7 == 0
then rangeK i j (k+1) (acc+1)
else rangeK i j (k+1) acc
| otherwise = acc

rangeJ :: Int - Int - Int - Int
rangeJ i j acc
| j  1000 = rangeJ i (j+1) (acc + rangeK i j 0 0)
| otherwise = acc

rangeI :: Int - Int - Int
rangeI i acc
| i  1000 = rangeI (i+1) (acc + (rangeJ i 0 0))
| otherwise = acc

C
main()
{
printf(%d\n, rangeI(0, 0));
return 0;
}

rangeK(i, j, k, acc)
{
if (k  1000) {
if (i * i + j * j + k * k % 7 == 0)
return rangeK(i, j, k+1, acc+1);
else
return rangeK(i, j, k+1, acc);
} else
return acc;
}

rangeJ(i, j, acc)
{
if (j  1000)
return rangeJ(i, j+1, acc + rangeK(i, j, 0, 0));
else
return acc;
}

rangeI(i, acc)
{
if (i  1000)
return rangeI(i+1, acc + rangeJ(i, 0, 0));
else
return acc;
}

I tried to keep both programs as similar as possible. I'm pretty
confident that the algorithm being executed are exactly the same. That
is, there's no lists being used vs. arrays or anything like that. I even
used Int instead of Integer to make sure an equivalent version of +, *
and mod are called (perhaps that was what I did wrong?)

I compiled the haskell code with ghc -O3 and I compiled the C code with
gcc -O3. The execution time of the programs were dramatically different.
You can test it yourselves, but here is the time I've got in my system:

The Haskell version:
real0m45.335s
user0m45.275s
sys 0m0.004s

against the C version:
real0m6.021s
user0m6.004s
sys 0m0.004s

Also, I found it interesting that a iterative version of that algorithm
in C ran in the same time as the recursive version. So it seems like gcc
was successfuly able to make those tail recursive functions into iterations.

It strikes me as surprising that Haskell would perform so much slower in
that example. I was expecting maybe a few seconds due to the garbage
collector or something like that, but not more than 7 times slower.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC vs GCC

2010-03-26 Thread Rafael Almeida
On Fri, Mar 26, 2010 at 10:42 PM, Bernie Pope florbit...@gmail.com wrote:
 On 27 March 2010 04:46, Rafael Cunha de Almeida almeida...@gmail.com wrote:

 During a talk with a friend I came up with two programs, one written in
 C and another in haskell.

 snip

 The Haskell version:
 real    0m45.335s
 user    0m45.275s
 sys     0m0.004s

 against the C version:
 real    0m6.021s
 user    0m6.004s
 sys     0m0.004s


 Could you please report which version of each compiler, which
 operating system, and which CPU?

My operating system is a Debian Lenny GNU/Linux, my CPU is:
$ grep 'model name' /proc/cpuinfo
model name  : Intel(R) Core(TM)2 Duo CPU T5550  @ 1.83GHz

I'm using ghc 6.8.2 and gcc 4.3.2, both from lenny package. I tried
the same code with ghc 6.12.1 and the result was the same:
real0m45.121s
user0m45.075s
sys 0m0.000s
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC vs GCC

2010-03-26 Thread Rafael Almeida
On Fri, Mar 26, 2010 at 6:49 PM, Jason Dagit da...@codersbase.com wrote:


 On Fri, Mar 26, 2010 at 2:33 PM, Bryan O'Sullivan b...@serpentine.com
 wrote:

 On Fri, Mar 26, 2010 at 10:46 AM, Rafael Cunha de Almeida
 almeida...@gmail.com wrote:

 During a talk with a friend I came up with two programs, one written in
 C and another in haskell.

 Your Haskell code builds a huge thunked accumulator value, so of course
 it's slow (put bang patterns on all arguments). Also, you should use rem
 instead of mod. Make those tiny changes and you'll get a 5x speedup, to half
 the performance of the C code.

 Interesting.  I had to add -fvia-C to get within half the performance of C.
 Just bang patterns and rem and I'm 1/5th of C.  I'm on a x86_64 machine.  I
 wonder if that plays in.

 Jason


Using bang patterns didn't help almost anything here. Using rem
instead of mod made the time go from 45s to 40s. Now, using -fvia-C
really helped (when I used rem but not using mod). It went down to
10s.

What's going on here? Doesn't ghc do tail recursion optimization?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Template Haskell

2010-03-19 Thread Rafael Almeida
I was reading the good old template haskell paper by Sheard and Peyton
Jones [1]. It looks like some API have changed, but things seems to be
more or less the same.

I got the printf example to run, and it is an alright example of
something to do with template haskell. You lose the ability to use a
dynamic generated string for the format, but that's not a practical
drawback (I can't think of a practical reason for using anything other
than a string literal for format anyway).

Anyhow, what is gained by the template programming in that case is
really the flexibility in the type system. You can generate the function
with the correct type on the fly, during compiling. That's nice enough,
but the article keeps saying that templates are nice for implementing
your own custom compiler optimizations. I can see that you really can do
so, but I fail to think of a good practical example where templates
would be hands down the best approach. Perhaps haskellers with more
experience have real life examples they've bumped into. So, please,
share your experience with us.

[1] 
http://research.microsoft.com/en-us/um/people/simonpj/papers/meta-haskell/meta-haskell.pdf
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Space leak

2010-03-13 Thread Rafael Almeida
On Sat, Mar 13, 2010 at 8:58 PM, Arnoldo Muller arnoldomul...@gmail.com wrote:
 Jason,

 I am trying to use haskell in the analysis of bio data. One of the main
 reasons I wanted to use haskell is because lazy I/O allows you to see a
 large bio-sequence as if it was a string in memory.
 In order to achieve the same result in an imperative language I would have
 to write lots of error-prone iterators. I saw lazy I/O as a very strong
 point in favor of Haskell.


What about mmap function? It's available on Linux, you can use it on C
and probably a lot of other imperative languages. Was the
non-portability factor the issue with using it?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GPL answers from the SFLC (WAS: Re: ANN: hakyll-0.1)

2010-03-05 Thread Rafael Almeida
On Fri, Mar 5, 2010 at 2:59 PM, Job Vranish job.vran...@gmail.com wrote:
 This seems really confusing.

 It would imply that if I write a library that is designed to talk to some
 part of the linux kernel API (which is GPL'd) then I'd have to release my
 library under the GPL. And anything that used my libraries API would need to
 be GPL'd too, etc...
 Which would mean that everything run in linux would need to be GPL'd, which
 is just silly.

Linux license specifically single that case out of the license
restrictions. From the COPYING file in linux's source:

   NOTE! This copyright does *not* cover user programs that use kernel
 services by normal system calls - this is merely considered normal use
 of the kernel, and does *not* fall under the heading of derived work.
 Also note that the GPL below is copyrighted by the Free Software
 Foundation, but the instance of code that it refers to (the Linux
 kernel) is copyrighted by me and others who actually wrote it.

 Also note that the only valid version of the GPL as far as the kernel
 is concerned is _this_ particular version of the license (ie v2, not
 v2.2 or v3.x or whatever), unless explicitly otherwise stated.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Function to detect duplicates

2010-02-25 Thread Rafael Gustavo da Cunha Pereira Pinto
Just to clarify the issue, I will propose the puzzle:

There is a single 10 digit number that:

1) uses all ten digits [0..9], with no repetitions
2) the number formed by the first digit (right to left, most significant) is
divisible by one
3) the number formed by the first 2 digits (again right to left) is
divisible by two
4) the number formed by the first 3 digits is divisible by three
 and so on, until:
11) the number formed by the first 10 digits (all!) is by 10

Actually this can be solved by a little logic, but I wanted to give a try on
brute force search using haskell.

I am not looking very large lists, but I was expecting a handful of small
lists.

My algorithm follow these steps:

1) start with an list of empty list ([[]]), call it ds
2) I cons each member of [0..9] to ds
3) filter using:
  a) noneRepeated
  b) (listToNum d) `mod` l == 0, where l is the length of each sublist d
(not computed, it is an accumulator that is incremented each time I cons)
4) repeat steps 2-3 until l==10


So, I represent each possible number as a reversed list of its digits... It
ran REALLY fast (sub-second).

So, bragging about Haskell with a Smalltalk-lover friend, by showing him how
clean was the code and how easy was to profile, I figured out that I spent
99% on noneRepeated.

After changing to the merge sort version, I have 30% on noneRepeated, 30% on
listToNum and 30% on putStrLn. Pretty good!

Besides, I could brag a little more about Hakell to that specific friend!!
;-)


Best regards to you all!!

Rafael


PS: Here is the original search code, with the bad noneRepeated and still
using length



import Data.List

digits=[0..9]

noneRepeated::[Integer]-Bool
noneRepeated=null.(filter (1)).(map length).group.sort

listToNum::[Integer]-Integer
listToNum = (foldl (\a x-10*a+x) 0).reverse

check::[Integer]-Bool
check ds= and [noneRepeated ds, (listToNum ds) `mod` l==0]
where l=fromIntegral $ length ds

nextlevel::[[Integer]]-[[Integer]]
nextlevel dss=filter (check) [d:ds | ds-dss,d-digits]

main=do
dss-runlevel 10 0 [[]]
print $ map (listToNum) dss

runlevel 0 b dds=return dds
runlevel a b dds=do
let dds'=nextlevel dds
putStrLn $ Level ++(show (b+1))++: ++(show $ length dds')++
matches
print $ map (listToNum) dds'
runlevel (a-1) (b+1) dds'
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Function to detect duplicates

2010-02-23 Thread Rafael Gustavo da Cunha Pereira Pinto
Hi folks,

While solving a puzzle, I was posed the problem of finding if there was no
duplicates on a list.

First I used:

noneRepeated=null.(filter (1)).(map length).group.sort


But this seemed very unneficient, so I thought that I could detect the
duplicates while sorting, and devised this:

import Control.Monad
import Data.Maybe

noneRepeated=isNothing . (foldl merge (Just [])) . (map sort) . pairs

pairs []=[]
pairs [x]=[[x]]
pairs (x:y:xs)=[x,y]:pairs xs

sort []=Just []
sort [x]=Just [x]
sort [x,y] | xy=Just [y,x]
   | yx=Just [x,y]
   | x==y=Nothing

merge::(Eq a, Ord a) = Maybe [a]-Maybe [a]-Maybe[a]
merge _ Nothing = Nothing
merge Nothing _ = Nothing
merge (Just []) (Just xs)=Just xs
merge (Just xs) (Just [])=Just xs
merge (Just (x:xs)) (Just (y:ys)) | x==y = Nothing
  | xy  = (Just y) +? (merge (Just (x:xs))
(Just ys))
  | xy  = (Just x) +? (merge (Just xs)
(Just (y:ys)))

(+?) = liftM2 (:)



My version of the merge sort returns Nothing whenever it finds two equal
entries, aborting all subsequent comparisons.

I have a few questions for the friendly people at this cafe:

1) Is there any improvement I can make?
2) Can it be parallelized (par, pseq)?


Best regards,

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


[Haskell-cafe] Haskell Platform

2010-01-21 Thread Rafael Gustavo da Cunha Pereira Pinto
Hi folks,

How are the efforts on Haskell Platform for GHC 6.12.1 going?

I'm considering joining those brave heroes. Where can I apply?


Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] parallel matrix multiply (dph, par/pseq)

2010-01-18 Thread Rafael Gustavo da Cunha Pereira Pinto
I never used DPH, but for Matrices, I always tend to use Array (Int,Int)
Double, as it accesses its elements in O(1). Arrays also can be unboxed
(UArray), which are much faster, or monadic and mutable (MArray), which are
more flexible.

I don't know if it is possible to use Arrays with DPH...




On Sun, Jan 17, 2010 at 21:35, Johannes Waldmann 
waldm...@imn.htwk-leipzig.de wrote:

 Hello.

 How can I multiply matrices (of Doubles)
 with dph (-0.4.0)?  (ghc-6.12.1)  -  I was trying

 type Vector = [:Double:]
 type Matrix = [:Vector:]

 times :: Matrix - Matrix - Matrix
 times a b =
  mapP
  ( \ row - mapP ( \ col - sumP ( zipWithP (*) row col  ) )
  ( transposeP b )
  ) a

 but there is no such thing as transposeP.

 When I try any kind of index manipulations,
 the compiler invariably tells me
 that it does not want to build  [: :] - lists of indices
 (e.g., there is no enumFromToP)
 (I guess because I'm using Data.Array.Parallel.Prelude.Double)

 Puzzled - J.W.


 PS: what's the recommended way to multiply matrices
 (better modelled as   Array (Int,Int) Double   or  [[Double]] ?)
 with the  par/pseq  approach (if this is recommended at all)?

 As I said earlier, I just want to have some nice and easy benchmarks
 for demonstration in a lecture (to be run on 2, 4, or 8 cores).
 Of course if they work, I'd use them in real life as well...




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




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Review request for my permutations implementation

2010-01-07 Thread Rafael Gustavo da Cunha Pereira Pinto
Hi,

Is there an entry in the haskell wiki for permutations? Since this is a
recurring topic, as primes, shouldn't we create a topic for that in the
wiki?

Regards,

Rafael


On Thu, Jan 7, 2010 at 08:46, Daniel Fischer daniel.is.fisc...@web.dewrote:

  Am Donnerstag 07 Januar 2010 09:37:42 schrieb CK Kashyap:

  Hi All,

 

  I've written this piece of code to do permutations -

 

  perms :: String - [String]

 Nothing in the algorithm needs the list elements to be Chars, there's no
 type class involved, so it should be

 perms :: [a] - [[a]]

  perms []= []

 This should actually be

 perms [] = [[]]

  perms (x:[])= [[x]]

 That is then superfluous.

  perms (x:xs)= concat (f [x] (perms xs))

 

 'f' is a good name for a function parameter, not for a top level binding.

 Why not

 perms (x:xs) = concat (map (spread [x]) (perms xs))

 whcih you can reformulate as

 perms (x:xs) = concatMap (spread [x]) (perms xs)

 or, if you like Monads, since concatMap is just the bind operator of the
 []-monad,

 perms (x:xs) = perms xs = spread [x]

 Which can be written as a simple do-block:

 perms (x:xs) = do

 prm - perms xs

 spread [x] prm

 or a list-comprehension

 perms (x:xs) = [permutation | tailPerm - perms xs, permutation - spread
 [x] tailPerm]

  spread :: String - String - [String] -- interpolate first string at

  various positions of second string spread str1 str2 = _spread str1 str2

  (length str2)

  where

  _spread str1 str2 0= [str1 ++ str2]

  _spread str1 str2 n= [(take n str2) ++ str1 ++ (drop n str2)] ++ (_spread

  str1 str2 (n-1))

 

 import Data.List

 spread short long = zipWith (\a b - a ++ short ++ b) (inits long) (tails
 long)

 If you only use spread for perms, you never interpolate anything but single
 element lists, so you might consider

 spread' :: a - [a] - [[a]]

 spread' x xs = zipWith (\a b - a ++ x:b) (inits xs) (tails xs)

 But if you import Data.List, you could also say

 perms = permutations

 and be done with it :) (except if you 1. need the permutations in a
 particular order, which is different from the one Data.List.permutations
 generates, or 2. you need it to be as fast as possible -
 Data.List.permutations was written to also cope with infinite lists, so a
 few things that could speed up generation of permutations for short lists
 couldn't be used).

  f xs = map (spread xs)

 

 

  The number of outcomes seem to indicate that correctness of the algo ..

 Apart from the case of empty input, it is correct.

  however, I'd be very obliged if I could get some feedback on the

  Haskellness etc of this ... also any performance pointers ...

 Re performance:

 I think the repeated (take k) and (drop k) in your spread are likely to be
 slower than using inits and tails, but it would need measuring the
 performance to be sure.

 I don't see anything that would automatically give bad performance.

 But there's the question of repeated elements.

 perms ab

 spills out 3628800 permutations, but there are only 252 distinct
 permutations, each of them appearing 120^2 = 14400 times.

 If your input may contain repeated elements and you're

 1. only interested in the distinct permutations (and 2.) or

 2. don't care about the order in which the permutations are generated,

 distinctPerms :: Ord a = [a] - [[a]]

 distinctPerms = foldr inserts [[]] . group . sort

 inserts :: [a] - [[a]] - [[a]]

 inserts xs yss = yss = (mingle xs)

 mingle :: [a] - [a] - [[a]]

 mingle xs [] = [xs]

 mingle [] ys = [ys]

 mingle xxs@(x:xs) yys@(y:ys)

 = [x:zs | zs - mingle xs yys] ++ [y:zs | zs - mingle xxs ys]

 generates the distinct permutations much faster if there are many repeated
 elements;

 if you want each distinct permutation repeated the appropriate number of
 times, the modification is easy.

 

 

  Regards,

  Kashyap


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




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Mysterious factorial

2009-12-30 Thread Rafael Gustavo da Cunha Pereira Pinto
fact2 is O(log n) while fact is O(n).

fact2 is partitioning the problem.

On Wed, Dec 30, 2009 at 08:57, Artyom Kazak artyom.ka...@gmail.com wrote:


 Why fact2 is quicker than fact?!

 fact2 :: Integer - Integer
 fact2 x = f x y
 where
 f n e | n  2 = 1
 | e == 0 = n * (n - 1)
 | e  0 = (f n (e `div` 2)) * (f (n - (e * 2)) (e `div` 2))
 y = 2 ^ (truncate (log (fromInteger x) / log 2))

 fact :: Integer - Integer
 fact 1 = 1
 fact n = n * fact (n - 1)

 I tried to write tail-recursive fact, fact as product [1..n] - fact2 is
 quicker!


 fact2 100 == fact 100 - I tested.

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




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Mysterious factorial

2009-12-30 Thread Rafael Gustavo da Cunha Pereira Pinto
fact2 sparks 2*n multiplications for every (n^2) factors

fact sparks n multiplications for every n factors


On Wed, Dec 30, 2009 at 10:13, Ralf Hinze ralf.hi...@comlab.ox.ac.ukwrote:

  fact2 is O(log n) while fact is O(n).
  fact2 is partitioning the problem.

 But fact2 sparks off two recursive calls. If we assume that
 multiplication is a constant-time operations, both algorithms
 have the same asymptotic running time (try a version that
 operates on Ints). For Integers, this assumption is, of course,
 false ...

 Cheers, Ralf

  On Wed, Dec 30, 2009 at 08:57, Artyom Kazak artyom.ka...@gmail.com
 wrote:
   Why fact2 is quicker than fact?!
  
   fact2 :: Integer - Integer
   fact2 x = f x y
   where
   f n e | n  2 = 1
  
   | e == 0 = n * (n - 1)
   | e  0 = (f n (e `div` 2)) * (f (n - (e * 2)) (e `div` 2))
  
   y = 2 ^ (truncate (log (fromInteger x) / log 2))
  
   fact :: Integer - Integer
   fact 1 = 1
   fact n = n * fact (n - 1)
  
   I tried to write tail-recursive fact, fact as product [1..n] - fact2
 is
   quicker!
  
  
   fact2 100 == fact 100 - I tested.
  
   ___
   Haskell-Cafe mailing list
   Haskell-Cafe@haskell.org
   http://www.haskell.org/mailman/listinfo/haskell-cafe
 




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] GHC 6.12 status and features

2009-12-12 Thread Rafael Gustavo da Cunha Pereira Pinto
THANKS!!

Just in time for Christmas!!




On Sat, Dec 12, 2009 at 12:22, Max Bolingbroke
batterseapo...@hotmail.comwrote:

 2009/12/12 Rafael Gustavo da Cunha Pereira Pinto 
 rafaelgcpp.li...@gmail.com:
  I know I should probably be asking to the GHC list, but is there any
 update
  on 6.12 since October? Any probable release date?

 It looks like haskell.org just acquired this page, though it's not yet
 linked to from anywhere else:

 http://haskell.org/ghc/download_ghc_6_12_1.html

  BTW, is there any feature list for the release?

 http://haskell.org/ghc/docs/6.12.1/html/users_guide/release-6-12-1.html

 Cheers,
 Max




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] GHC 6.12 status and features

2009-12-11 Thread Rafael Gustavo da Cunha Pereira Pinto
Hi folks, and specially Simon Marlow,


I know I should probably be asking to the GHC list, but is there any update
on 6.12 since October? Any probable release date?

BTW, is there any feature list for the release?


Thank all of you involved in bringing this new version to life. GHC rocks!


Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Is it possible: Haskell platform - portable edition

2009-12-07 Thread Rafael Gustavo da Cunha Pereira Pinto
Hello,

Has anyone considered the possibility of making a *Portable* Haskell
Platform distribution (portable meaning on a USB stick) for Windows?

This worked form me: I installed GHC on one machine, copied it to a USB
stick and created a batch to set the environment path and open a command
prompt.

This gives me the freedom to use Haskell wherever I am! The only downside is
that I have to edit packages.conf by hand everytime I install a package.


I would like to improve this, by making it more automatic. Do you haskellers
think it is possible?

Regards,

Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Could someone teach me why we use Data.Monoid?

2009-11-13 Thread Rafael Gustavo da Cunha Pereira Pinto
Disclaimer: I don't really know all about category theory, so some
definitions might not be absolutely correct.

Monoid is the category of all types that have a empty value and an append
operation.

The best example is a list.

instance Monoid [a] where
mempty  = []
mappend = (++)


Why do I need it? Well, you can think of a function where you need to
incrementally store data.

Storing them to a Monoid, you can start with a list and then change to a
Set, without changing the function itself, because it would be defined based
on the Monoid operations.

instance Ord a = Monoid (Set a) where
mempty  = empty
mappend = union
mconcat = unions

Hope I have helped!

Regards,

Rafael



On Fri, Nov 13, 2009 at 14:14, Magicloud Magiclouds 
magicloud.magiclo...@gmail.com wrote:

 Hi,
  I have looked the concept of monoid and something related, but
 still, I do not know why we use it?

 --
 竹密岂妨流水过
 山高哪阻野云飞

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




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Could someone teach me why we use Data.Monoid?

2009-11-13 Thread Rafael Gustavo da Cunha Pereira Pinto
*...in my humble opinion. (Which, obviously, nobody else will agree with.)
*

I somewhat agree with your opinion!!

What I miss the most is practical examples:

1) A function that uses a Monoid as a container
2) A function that uses Monoid as algebra

and so on, for most of categories.

I had a hard time understanding monads, not because I didn't understand the
concept of a monad, but because practical uses are missing, except on
Wadler's paper!

Regards

Rafael

On Fri, Nov 13, 2009 at 14:52, Andrew Coppin andrewcop...@btinternet.comwrote:

 Stephen Tetley wrote:

 2009/11/13 Rafael Gustavo da Cunha Pereira Pinto 
 rafaelgcpp.li...@gmail.com:


 Monoid is the category of all types that have a empty value and an append
 operation.




 Or more generally a neutral element and an associative operation:

 The multiplication monoid (1,*)

 9*1*1*1 = 9

 1 is neutral but you might be hard pressed to consider it _empty_.



 This is the thing. If we had a class specifically for containers, that
 could be useful. If we had a class specifically for algebras, that could be
 useful. But a class that represents any possible thing that can technically
 be considered a monoid seems so absurdly general as to be almost useless.
 If you don't know what an operator *does*, being able to abstract over it
 isn't especially helpful...

 ...in my humble opinion. (Which, obviously, nobody else will agree with.)


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




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Best Editor In Windows

2009-10-16 Thread Rafael Gustavo da Cunha Pereira Pinto
Real programmers use butterflies!!

http://xkcd.com/378/


The best editor is the one that suites YOU better. I use VIM, even in
Windows, but that's me!

Best regards,

Rafael


On Fri, Oct 16, 2009 at 07:32, Peter Verswyvelen bugf...@gmail.com wrote:

 If you're a Windows developer and don't want to spent time to learn all the
 alien emacs keyboard shortcuts, you can get going quickly by using this
 emacs patch:
 http://ourcomments.org/Emacs/EmacsW32.html

 http://ourcomments.org/Emacs/EmacsW32.htmlThen use set all to
 Emacs!W32 and your keys behave like all other editors on Windows.

 Of course I guess the Emacs shortcuts are deliberately chosen the way they
 are, but using these Emacs shortcuts makes it hard to also use any other
 editor on Windows IMO.

 On Fri, Oct 16, 2009 at 11:29 AM, Deniz Dogan 
 deniz.a.m.do...@gmail.comwrote:

 2009/10/16 Gregory Crosswhite gcr...@phys.washington.edu:
  In my humble opinion, one of the best editors for development of all
 time is
  Leo:
 
 http://webpages.charter.net/edreamleo/front.html
 
  Leo takes the idea of code folding and gives you complete control over
 it.
   That is, unlike other editors which only let you fold the code inside
  if/while/for/etc. statements and which only show you an outline
 consisting
  of a level for files and a level for function, Leo lets you structure
 the
  levels of your outline arbitrarily so that you can fold arbitrary
 chunks
  of code and do things like grouping together functions and files with a
  similar purpose or implementation.  By structuring your code as an
 outline,
  you make it easier for others and yourself both to navigate through the
 code
  and also to see at a glance the high-level structure.
 
  Anyway, just wanted to use this opportunity to plug my favorite tool.
  :-)
   The downside about it is that the implementation sometimes feels a bit
 slow
  and clunky, so part of me really hopes that at the very least people
 will
  learn enough about this tool to take its ideas and steal them for other
  editors!
 
  Cheers,
  Greg
 

 This should come as no surprise, but Emacs can do this as well.

 --
 Deniz Dogan
 ___
 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




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: A thought about liberating Haskell's syntax

2009-09-29 Thread Rafael Gustavo da Cunha Pereira Pinto
Hmm... Simon, was it a typo? Is it 6.10.x or 6.12?

Regards,

Rafael

2009/9/29 Simon Peyton-Jones simo...@microsoft.com

 Type splices are implemented in the upcoming GHC 6.10.

 Simon

 | -Original Message-
 | From: haskell-cafe-boun...@haskell.org [mailto:
 haskell-cafe-boun...@haskell.org] On
 | Behalf Of George Pollard
 | Sent: 16 September 2009 13:45
 | To: Haskell Café
 | Subject: [Haskell-cafe] Re: A thought about liberating Haskell's syntax
 |
 | Also (sorry for the triple-post!) I noticed that in the TH
 | documentation, it says:
 |
 | Type splices are not implemented, and neither are pattern splices
 |
 | This means, while we could write a preprocessor that would give us, e.g.:
 |
 | x :: Set Int
 | x = {1,2,3,4}
 |
 | We cannot splice in the right places to allow:
 |
 | x :: {Int}
 | x = {1,2,3,4}
 |
 | isSetEmpty :: {a} → Bool
 | isSetEmpty {} = True
 | isSetEmpty _ = False
 | ___
 | 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




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Plotting parametric functions in Haskell

2009-09-14 Thread Rafael Almeida
On Mon, Sep 14, 2009 at 6:37 AM, Peter Verswyvelen bugf...@gmail.com wrote:
 I did that once a long time ago using GTK2HS; but I don't have that
 code anymore I think, it was a quick hack anyway.

 Doing a search for plot on Hackage revealed
 http://hackage.haskell.org/package/Chart
 http://hackage.haskell.org/package/gnuplot

 Maybe that helps.


I probably should have mentioned that I really want to plot a 3D
function. I've seen those packages before, but I didn't even tried
them out. Chart seems to be only for 2D stuff and the reason why I was
looking for haskell solutions is because I don't really like gnuplot
for 3D plotting. Maybe I'm the one who doesn't get gnuplot's
interface, but I find it awful to navigate through a 3D graph using
gnuplot.

Thanks for the answer, though.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Plotting parametric functions in Haskell

2009-09-13 Thread Rafael Cunha de Almeida
Hello,

I think it would be interesting to plot and visualize parametric (and
other kind of functions) using the haskell language to define them
[functions]. Does anyone know about some software or API that does just
that? I started writing a plotter to do that using hopengl. But my
computer graphics skills are rather bad and I couldn't produce anything
really useful.

[]'s
Rafael

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


Re: [Haskell-cafe] Re: [Haskell] Looking for a new HWN editor

2009-09-08 Thread Rafael Almeida
On Tue, Sep 8, 2009 at 8:16 AM, Benjamin
L.Russelldekudekup...@yahoo.com wrote:
 On Sat, 5 Sep 2009 19:34:24 -0400, Brent Yorgey
 byor...@seas.upenn.edu wrote:

On Sat, Sep 05, 2009 at 05:26:08PM -0400, Brent Yorgey wrote:
 Executive summary:

   * I'm looking for someone to take over as HWN editor
   * It is highly automated and doesn't take as much time as you might
     think (about 3-4 hours/week on average)
   * You DON'T need to be a Haskell guru
   * It is far from a thankless job and is a fun way to provide an
     appreciated service to the community!

The position has been filled!  More details to come.

 Wow!  That was a quick decision!  Most Haskell users probably didn't
 even have time to read the announcement before the position was
 filled; I certainly did not.

 Well, since this position has already been filled, there's probably
 not much that can be done (other than ask the new editor and hope that
 he/she is understanding), but just to give a fair opportunity to all
 Haskell users, if the editor changes again, it may be helpful at least
 to give everybody an opportunity to read the announcement and apply
 for the position.

 Just my two cents


I don't think that's really necessary. I suppose there's no reason for
more people to be editors if the demand is high. It could even
eventually have its own articles and perhaps and bigger summaries
about the threads.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ANNOUNCE: Palindromes 0.1

2009-09-07 Thread Rafael Cunha de Almeida
Johan Jeuring wrote:
 Palindromes
 ==
 
 Palindromes is a package for finding palindromes in files.
 
 Visit the homepage
 
   http://www.jeuring.net/Palindromes/
 

A few options are not working well:
$ ./palindromes --h
*
* Palindrome Finder *
*
palindromes: --h: openFile: does not exist (No such file or directory)
$ cat f
socorram-me subi no onibus em marrocos
$ ./palindromes -tl f
*
* Palindrome Finder *
*
Usage:

palindrome [command-line-options] input-file

The following options are available:
  --h: This message
  -p : Print the longest palindrome (default)
  -ps: Print the longest palindrome around each position in the input
  -l : Print the length of the longest palindrome
  -ls: Print the length of the longest palindrome around each position
in the input
  -t : Print the longest palindrome ignoring case, spacing and punctuation
  -tl: Print the length of the longest text palindrome
$
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Problem building encoding-0.6.0: missing Data.CharMap.Builder

2009-08-24 Thread João Rafael Nicola
Hi,

I am trying to install the encoding-0.6.0 package, but it complains that
that package Data.CharMap.Builder is missing. I could not find any
reference to that package anywhere on the web. Does anyone know where I can
find it or a workaround?

Thanks,

João Rafael

 cabal install encoding

Resolving dependencies...

/tmp/encoding-0.6.08632/encoding-0.6.0/Data/Encoding/Preprocessor/XMLMappingBuilder.hs:11:7:
Could not find module `Data.CharMap.Builder':
  Use -v to see a list of the files searched for.
cabal: Error: some packages failed to install:
encoding-0.6.0 failed during the configure step. The exception was:
exit: ExitFailure 1
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [Haskell] ANNOUNCE: GLUT 2.2.1.0

2009-08-17 Thread Rafael Gustavo da Cunha Pereira Pinto
On Mon, Aug 17, 2009 at 03:17, Sven Panne sven.pa...@aedion.de wrote:

 Am Sonntag, 16. August 2009 22:10:23 schrieb Rafael Gustavo da Cunha
 Pereira
 Pinto:
  BTW, as an enhancement for 2.2.2.0, you could treat unnamed mouse
 buttons.
  Mouses with more axis and more buttons are becoming increasingly common,
  and unmarshalMouseButton is not prepared to accept them!!
 
  Here are exceptions I caught, playing with my Genius Traveler 515 mouse:
 
  unmarshalMouseButton: illegal value 5
  unmarshalMouseButton: illegal value 6
  unmarshalMouseButton: illegal value 7
  unmarshalMouseButton: illegal value 8

 Good point, I had similar reports already, but I simply forgot to handle
 this
 in yesterday's release. The right way to handle this would probably be
 extending the MouseButton data type with an 'AdditionalButton Int'
 constructor
 and simply pass the unknown button numbers via this case. I am not so sure
 about a nice name for this constructor: AdditionalButton? GenericButton? Or
 simply MouseButton, just like the type itself?

 Cheers,
S.


AdditionalButton seems good. My second choice would be to use MouseButton.




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: [Haskell] ANNOUNCE: GLUT 2.2.1.0

2009-08-16 Thread Rafael Gustavo da Cunha Pereira Pinto
Thanks Sven!

BTW, as an enhancement for 2.2.2.0, you could treat unnamed mouse buttons.
Mouses with more axis and more buttons are becoming increasingly common, and
unmarshalMouseButton is not prepared to accept them!!

Here are exceptions I caught, playing with my Genius Traveler 515 mouse:

unmarshalMouseButton: illegal value 5
unmarshalMouseButton: illegal value 6
unmarshalMouseButton: illegal value 7
unmarshalMouseButton: illegal value 8


Anyway, keep the good work!

Best Regards,

Rafael



On Sun, Aug 16, 2009 at 13:12, Sven Panne sven.pa...@aedion.de wrote:

 A new version of the GLUT package has been uploaded to Hackage.

  * The package is now autoconf-free. API entries are resolved dynamically
 at
 runtime, just like the OpenGLRaw and GLURaw packages.

  * Support for sRGB framebuffers has been added, just use SRGBMode with
 initialDisplayMode. To use this functionality, you need the upcoming
 freeglut
 2.6.0 library, older versions and classic GLUT do not support this
 feature.

  * Support for context profiles has been added via initialContextProfile.
 Again, this works with the upcoming freeglut 2.6.0 library only.

 Cheers,
S.
 ___
 Haskell mailing list
 hask...@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: OpenGL 2.3.0.0

2009-07-31 Thread Rafael Gustavo da Cunha Pereira Pinto
Carter,

It seems you need to install opengl-dev or something like that in your Linux
instalation (using apt-get, yum or similar tool).

Regards,

Rafael

On Fri, Jul 31, 2009 at 17:24, Carter Schonwald
carter.schonw...@gmail.comwrote:

 I just the the rebuild of the haskell glut / opengl libs and I got the
 following message
 Configuring OpenGLRaw-1.0.1.0...
 cabal: Missing dependency on a foreign library:
 * Missing C library: GL
 This problem can usually be solved by installing the system package that
 provides this library (you may need the -dev version). If the library is
 already installed but in a non-standard location then you can use the flags
 --extra-include-dirs= and --extra-lib-dirs= to specify where it is.
 cabal: Error: some packages failed to install:
 GLURaw-1.0.0.0 depends on OpenGLRaw-1.0.1.0 which failed to install.
 OpenGL-2.3.0.0 depends on OpenGLRaw-1.0.1.0 which failed to install.
 OpenGLRaw-1.0.1.0 failed during the configure step. The exception was:


 and I don't see how to get the openglraw to build or what has changed

 thanks for any help
 -Carter

 On Thu, Jul 30, 2009 at 8:23 PM, Rafael Gustavo da Cunha Pereira Pinto 
 rafaelgcpp.li...@gmail.com wrote:

 Here is a patch that makes it compile, but then it breaks all code
 developed for GLFW-0.3, as all Floats need to be changed to CFloat.

 For all haskellers here:

 Sorry for all this annoyance, but I was starting to study those libraries
 (OpenGL, GLUT and GLFW) using Haskell and the update broke some of my code.


 Best Regards,

 Rafael


 ___
 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




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: OpenGL 2.3.0.0

2009-07-30 Thread Rafael Gustavo da Cunha Pereira Pinto
BTW, OpenGL-2.3 breaks GLFW-0.3



On Wed, Jul 29, 2009 at 22:47, Felipe Lessa felipe.le...@gmail.com wrote:

 On Wed, Jul 29, 2009 at 10:24:23PM -0300, Rafael Gustavo da Cunha Pereira
 Pinto wrote:
  mapAccumL was added to Data.Traversable in package base-4. GHC 6.8.2 uses
  base-3...

 But this means that Tensor's dependencies should be on base = 4, not 3.

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




-- 
Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: OpenGL 2.3.0.0

2009-07-29 Thread Rafael Gustavo da Cunha Pereira Pinto
Just a heads up:

I did a cabal install Tensor on my Ubuntu box, and got the following
message:

src/Data/Tensor.hs:333:18: Not in scope: `mapAccumL'

I will investigate a little more and let you know.



On Wed, Jul 29, 2009 at 13:55, Felipe Lessa felipe.le...@gmail.com wrote:

 On Wed, Jul 29, 2009 at 06:26:30PM +0200, Sven Panne wrote:
  Apart from that, a bug in vertexAttribPointer has been fixed.

 ...and the new ObjectName, StateVar and Tensor packages are being
 used, and this is great!  Thanks for the release.

 --
 Felipe.
 ___
 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


Re: [Haskell-cafe] Re: [Haskell] ANNOUNCE: OpenGL 2.3.0.0

2009-07-29 Thread Rafael Gustavo da Cunha Pereira Pinto
That was quick!

mapAccumL was added to Data.Traversable in package base-4. GHC 6.8.2 uses
base-3...

I think I will be forced to upgrade my GHC by hand... I just can't stand
6.8.2 anymore...



On Wed, Jul 29, 2009 at 22:17, Rafael Gustavo da Cunha Pereira Pinto 
rafaelgcpp.li...@gmail.com wrote:

 Just a heads up:

 I did a cabal install Tensor on my Ubuntu box, and got the following
 message:

 src/Data/Tensor.hs:333:18: Not in scope: `mapAccumL'

 I will investigate a little more and let you know.





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


[Haskell-cafe] ICFP contest write-up

2009-07-20 Thread Rafael Gustavo da Cunha Pereira Pinto
For all Portuguese reading haskellers, I am describing my ICFP 2009 contest
write-up on my blog. Feel free to comment.

http://rafaelgcpp.blogspot.com/search/label/ICFP2009


For the non-Portuguese readers, Google translation tools do a lousy job, but
it is still readable.

Regards

Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Haskell Platform on Ubuntu

2009-07-08 Thread Rafael Gustavo da Cunha Pereira Pinto

 The Ocaml programming language has exactly the same problem, but
 the Debian Ocaml maintainers have automated the process and last
 time to Ocaml compiler version was updated over 95% of all Ocaml
 libraries were rebuilt within 24 hours.



Since I never built GHC from scratch, it is really hard for me to estimate
how much effort would I have to put through to automate the whole building
process.

Anyway, automating the package building process is crucial for Linux
distributions.

One problem I see is the binary-only distribution of packages. This makes
cabal-install incompatible with most distributions except, maybe, gentoo.
The automation process would have to run through hackageDB tracking
dependencies and compiling each needed library. Pretty hard stuff...


Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell Platform on Ubuntu

2009-07-06 Thread Rafael Gustavo da Cunha Pereira Pinto
Is there anyone working on a Haskell Platform package for Ubuntu?

GHC in Ubuntu is a pain!


Regards

Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell Platform on Ubuntu

2009-07-06 Thread Rafael Gustavo da Cunha Pereira Pinto
Thanks.  I may even be the one to step up, if nothing happens till 9.10... I
really miss up-to-date ghc in Ubuntu.



2009/7/6 Don Stewart d...@galois.com

 RafaelGCPP.Linux:
 
  Is there anyone working on a Haskell Platform package for Ubuntu?
 
  GHC in Ubuntu is a pain!

 The Debian team is working on packaging, but until then (or if someone
 on Ubuntu steps up), you'll need to use the Unix tarball:


 http://hackage.haskell.org/platform/2009.2.0.1/haskell-platform-2009.2.0.1.tar.gz

 -- Don




-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] On the parallel between java annotations and monads

2009-07-03 Thread Rafael Almeida
Hello,

After an extensive search (5 minutes googling) I could not find any comparison
between Java annotations (or Python annotations for that matter) and Monads. I
think they are similar in various aspects and I want to discuss them here.

I'm sure several of you have experience with Java programming and its annotation
system. At first they seem like an extension to the typing system, by using
annotations a single variable or method may have more than one type: the real
type and all the annotations types. The way you declare them is not important
for this discussion, but assume that you've created the annotations
GreaterThanFive and LessThanTwenty, you could annotate a method like
this (let's
forget about all the class verbosity for a while):

@GreaterThanFive @LessThanTwenty int doYourThing();

You could than use reflection to read those annotations and you could check if
the returned integer is in the correct range. You could even make the compiler
generate code that will do that checking automatically for you.

Even though that was my first impression of them, that's not really
how they are
used in practice (at least the practice that I have experimented). People use
them to implement Monad-like features to the language. Actually, you can forget
monad and think of computation containers.

On an EJB environment there's something called a container and it will do all
sorts of computations when you call an annotated method or when you
create a new
annotated class. For instance, if, inside of an entity bean, you annotate a
variable like this:

@Column(name = NAME) private String name;

then, when you create a method like so:

public String getName()
{
return name;
}

that name is actually something retrieved from the database, even though, it
looks just like something in memory. As far as I know the interaction with
monads for handling databases is not very different. There are other annotations
which allows the container to inject some object on a variable, such as:

@PersistenceContext private EntityManager entityManager;

now you won't even create an EntityManager instance, but will use the object
living inside the container. I compare that to getting a value from an State
Monad. Like there, you'll do some computations using entityManager, but it will
ultimately be returned to the container.

While each computational container in Haskell is very rigid and well
defined, in
java there's nothing rigorous about the annotation. However, quite often the
annotations in Java are used in a manner similar to the implementation of a
Monad in Java.

[]'s
Rafael
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Reflections on Haskell and ICFP Contest 2009

2009-06-29 Thread Rafael Gustavo da Cunha Pereira Pinto
Hi All,

As the ICFP 2009 contest (http://www.icfpcontest.org) approaches its end, I
decided to write down some thoughts I had while trying.

On Friday I downloaded the task (http://www.icfpcontest.org/task-1.9.pdf),
read it for a while, and, since my goal is to finish by Xmas, went to the
swimming pool. :-D While swimming, I started to think on the problem, and
realized that the task is almost too easy for Haskell. Actually the task was
so easy, that they added a final, non-scoring, task for those who have
finished early.

This year's task is to build a VM that runs a (simple) program that
simulates the physics of a satellite. The VM code has no branches, acting
like a huge pocket calculator. The mission is to create a simulator that
interact with this VM and maneuver the sattelite(s) on predefined patterns.

Here is how it went:

1) Reading the orbiter data file:

The orbiter data file is a stream of 32-bit unsigned integers, which are
commands, and 64-bit double precision IEEE-754 floats, which are data,
forming a 96-bit frame. For this part I decided to use the Data.Binary
module from hackage. The module is great, and it is very simple to use. But
that took me 3 hours to learn how to use it (which, with my honey-do list
ended up to be in Sunday morning)

By Saturday night I was cursing The Binary Strike Force because

  a) get :: Word32 reads it in little-endian
  b) get :: Double reads the result of an decodeFloat, which has no
resamblance at all with IEEE-754 standards
  c) I spent the entire Saturday (2 hours, honey-do excluded)
thinking I was doing something wrong!!

I was really pissed of, until I found getWord32le and getWord64le, which
solved 80% of the problem. The final blow was to decode the Word64 encoded
IEEE-754 float into a Haskell float, which took me another honey-do-free
hour.

First step solved. (BTW: I am attaching the first version to this e-mail. I
will upload to Hackage upon completion, when getIEEE754float64le and
putIEEE754float64le functions are done!)

2) Running the VM:

This is the step I am working on. A really good and obvious approach to run
the VM is to use a RWS monad, since:

 a) I have a fixed environment (the program and the input ports)
 b) I have a state (the program counter, the status register and the
data memory contents)
 c) I have a monoid output (the output ports)

This is my recurrent complaint (a rant, maybe): this really important monad
is completely undocumented, left for the developer to figure out how to use
it. Even each of the singular monads (Reader, Writer and State) is poorly
documented.

I will do some toy programs to understand each one. Let's hope I can create
a hands-on tutorial on the RWS monad.

3) Controlling the sattelites

This is going to be a piece of cake (aheeem! Just kidding!!). After
computing the VM iteration, another computation will take the output data
time series and estimate the next move.

It will be a piece of cake, considering I would have learned enough of
Haskell state monads on step 2 to have just to worry about the physics of
the problem!!!


I'll keep you updated as my tests go, and hopefully I will have a working
demo of the task written in Haskell by Xmas... 2010! ;-)

Best regards,

Rafael Gustavo da Cunha Pereira Pinto


IEEEFloat.hs
Description: Binary data
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Reflections on Haskell and ICFP Contest 2009

2009-06-29 Thread Rafael Gustavo da Cunha Pereira Pinto
Hi Tuh2009/6/29 minh thu not...@gmail.com


  First step solved. (BTW: I am attaching the first version to this e-mail.
 I
  will upload to Hackage upon completion, when getIEEE754float64le and
  putIEEE754float64le functions are done!)

 Indeed, I found the binary format a difficulty for haskell. But in
 fact, hackage has a module that does the work:
 http://hackage.haskell.org/package/data-binary-ieee754


Shame on me! :-(
If only I have posted this rant earlier! :-D


 2) Running the VM:
 
  This is the step I am working on. A really good and obvious approach to
 run
  the VM is to use a RWS monad, since:
 
   a) I have a fixed environment (the program and the input ports)
   b) I have a state (the program counter, the status register and
 the
  data memory contents)
   c) I have a monoid output (the output ports)
 

 Why a monad ? Why not just a function State - State and the use a function
 like
 iterate to do the work ?


I am considering that using the monad all the state and environment
threading will be simplified. The output part is optional.

But you are absolutely right, I could use a state composed by (Inputs,
program counter, status, data), which would do just as well, as it is just a
matter of not touching the program and the input.



  3) Controlling the sattelites
 
  This is going to be a piece of cake (aheeem! Just kidding!!). After
  computing the VM iteration, another computation will take the output data
  time series and estimate the next move.

 The next move is easy to estimate : you have the vm and simulating code at
 hand.
 Of course, making the best move is another problem.


I think the simulator itself is another State-State function, but this time
the state is a [Output].


 Good luck !


Thanks!


 Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Reflections on the ICFP 2009 programming contest

2009-06-29 Thread Rafael Gustavo da Cunha Pereira Pinto
I spent too much time reading the files, until today, when Minh Tuh pointed
me the right direction on reading the floats...

Anyway, I will still keep trying until Xmas :-)



On Mon, Jun 29, 2009 at 15:40, Justin Bailey jgbai...@gmail.com wrote:

 Anyone have thoughts to share? I'd love to read others' experiences
 but there isn't much coming up with searches or on redditt ...

 I was happiest with the VM I implemented. Sadly, I wasn't able to
 solve any of the scenarios, but my VM ran damn fast. That didn't seem
 to matter so much this year as it did two years ago - I think I am
 still scarred by Endo's DNA ..

 Anyways, for those who care, the heart of my VM implementation was a
 monadic fold over the program, with a mutable array representing the
 machine's memory, all inside ''runSTUArray.'' I used a simple data
 type to represent the machine:

 data Machine = Machine { instrs :: [OpCode]
   , dataMem :: UArray Int Val
   , outputs :: UArray Int Val
   , status :: !Int
   , inputs :: IntMap Val }

 where ''dataMem'' holds the data memory area. To execute a program, I
 folded over the ''instrs'' list and updated memory as I went:

 exec :: Machine - Input - Machine
 exec m@(Machine { instrs = instrs }) inps =
let m' = m { inputs = readInputs inps }
newMem = runSTUArray $ do
mem' - thaw (dataMem m)
foldM (step m') mem' (zip instrs [0..])

 I considered ''unsafeThaw'' in the above, but performance didn't hurt
 me much and it seemed safer. Since I was recording all output I was
 worried that would break referential integrity. In any case, when the
 fold was finished I just assigned ''newMem'' to the new machine and
 moved to the next iteration.

 ''step'' takes the mutable array and updates it while the program
 executes. I won't show the whole body, as it just a separate
 definition for each opcode, just the type:

  step :: Machine - STUArray s Int Val - (OpCode, Addr) - ST s
 (STUArray s Int Val)

 The only downside to this approach was the machine had three mutuable
 states: memory, output, and status. runSTUArray only wants to return a
 single array so inside step I had to hold all values in one array. Not
 a big deal but a little ugly.

 I kept a diary of my experience over the weekend at
 http://icfp2009.codeslower.com. I started out with such optimism ...
 Stil, I'm glad to have done it. Lots of fun! My thanks to the
 organizers!
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe




-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Reflections on Haskell and ICFP Contest 2009

2009-06-29 Thread Rafael Gustavo da Cunha Pereira Pinto
2009/6/29 Lanny Ripple la...@cisco.com

 When you get bored or stumped with the problem you might pass your
 time with Orbiter [http://orbit.medphys.ucl.ac.uk/].  Or you could
 just use all the orbital mechanics math from the documentation.  :)

  Enjoy,
  -ljr


That's cool... I'll try it someday!
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] ICFP contest

2009-06-24 Thread Rafael Gustavo da Cunha Pereira Pinto
Last year I teamed up with a guy at work who had no knowledge of any
functional programming language whatsoever. Actually, his main dialect is
C++.

We ended up trying to use plain C++, but it took us almost 6 hours to put
network and string decoding routines to work. I gave up mainly because in
Python, Perl, or even Haskell, it would have taken me 15 minutes or so!

The main problem was not C++, it was the lack of a good application
framework and the time spent planning (efficient) data structures. Later we
figured out that Boost could have helped us, but neither one had enough
experience with the libraries to use it...

This year I will try to use Haskell, then Python, on a team all by myself. I
will also relax my objectives: instead of winning the contest, my goal will
be to complete the task before Xmas! :-D

Best regards



2009/6/24 Max Rabkin max.rab...@gmail.com

 I'm part of a fairly large team. I'm the only person on the team who's
 done more than Project Euler problems in Haskell, so we'll probably
 only use Haskell if there's a library or program that does exactly
 what we need for some task. Likely we'll be using Perl and Python, and
 C++ if there's any heavy lifting to be done.

 --Max

 2009/6/23 Rafael Gustavo da Cunha Pereira Pinto 
 rafaelgcpp.li...@gmail.com:
  Hi,
 
  The good folks here are really quiet about the ICFP Contest. Is anyone
  participating this year?
 
  As in the previous four years, I will probably download the problem, take
 a
  look, and try for a while... Having a family don't allow me to go much
  further, especially when teaming up with myself!
 
  Best regards,
 
 
  Rafael Gustavo da Cunha Pereira Pinto
 
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 




-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ICFP contest

2009-06-23 Thread Rafael Gustavo da Cunha Pereira Pinto
Hi,

The good folks here are really quiet about the ICFP Contest. Is anyone
participating this year?

As in the previous four years, I will probably download the problem, take a
look, and try for a while... Having a family don't allow me to go much
further, especially when teaming up with myself!

Best regards,


Rafael Gustavo da Cunha Pereira Pinto
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Function to cast types

2009-03-22 Thread Rafael Cunha de Almeida
John Dorsey wrote:
 Anonymous One,
 
 I'm new to haskell, I'm wondering how can you write a function that will do
 the following:
 fromIntToString :: Int - String
 
 Is this a homework assignment, perchance?  Please take a look at
 http://www.haskell.org/haskellwiki/Homework_help
 Everyone here is glad to help, but we're also sensitive on academic
 honesty.
 

This e-mail is offtopic, but I suppose being a little offtopic every now
and then isn't that bad, specially if the subject is interesting. So,
here I go.

The only reason people would want the answer of an assignment instead of
actually doing it themselves is if they don't care about actually doing
it. That is, they don't want to learn haskell, they just want to pass a
class. In that case, do we really want to _make_ them learn?

You could argue that helping someone pass some class without learning is
not worth your time. I wouldn't try to convince you otherwise. But if
you thought the assignment was interesting and you did it yourself, I
see no problem with sharing that with the person who asked it. The
bottom line is that I don't believe in making people learn things they
are not interested in learning in the first place.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Sometimes I wish there was a global variable

2009-03-22 Thread Rafael Cunha de Almeida
Maurí­cio wrote:
 Notice that rotX, rotY and pos are meant to be used as comunication
 between the keyboardMouse and display functions. They need to be set as
 0 first, so display won't do anything. Only when they user press a few
 buttons that those values change, so display behaves accordanly.

 In a state-based language I would place display and keyboardMouse in one
 module and let them communcate to each other like they want. In haskell,
 I'm not quite sure how to do it except by that parameter passing style.
 
 In one module, you can write:
 
 --
 giveMeFunctions = do {
 newIORef ...
 newIORef ...
 newIORef ...
 (...)
 let f1 = ...
 let f2 = ...
 return (f1,f2)
 --
 
 and in the main:
 
 (keyboardMouse,display) - giveMeFunctions
 

Doing it like that I could have all the definitions in one module, but
it doesn't solve another important problem: keyboardMouse and display
functions have to have as many parameters as there are IORefs.

In my particular case, since I find out what key the use has pressed
through pattern matching, keyboardMouse has several definitions. So
adding a new IORef means adding a wildcard parameter to each
keyboardMouse definition. As well as a new parameter to the display
function. Which looks a bit clumbersome to me.

In a state-based language I'd have something in the lines of:
switch (key) {
case LEFT_KEY :
/* using var1 ... */
case RIGHT_KEY :
/* using var2 ... */
}
then, handling a new case would be a matter of adding a global
variable and adding a new case in the end of the function containing
the switch.

Whereas in Haskell I would have something like
keyboard var1 _ LeftKey = ...
keyboard _ var2 RightKey = ...
If I wanted to add a new IORef I'd have to do something like:
keyboard var1 _ _ LeftKey = ...
keyboard _ var2 _ RightKey = ...
keyboard _ _ var3 RightKey = ...
So, I had to change all previous definitions.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] ghci + hopengl

2009-03-21 Thread Rafael Cunha de Almeida
Hello,

I'm writing a program for plotting vectorial functions and maybe
something else in the future. My goal is to be able to have the
following usage:

Prelude :l Galo.hs
Prelude Galo show3Dvec (\t - (t, t, 0)) [0.0,0.01 .. 1.0]
* shows graph *
Prelude Galo show3Dvec (\t - (t, t**2, 0)) [0.0,0.01 .. 1.0]
* shows new graph *

I already done something, the main module can be found here:


http://github.com/aflag/galo/blob/0a54a53db0f66384cfc0775f12582931d0fb4205/Galo.hs

The whole project is found here:

http://github.com/aflag/galo/tree/master

I think mainLoop is somehow responsible to exit the whole thing. I
tried to even call that function through forkIO. But didn't work quite
well: my terminal started behaving really weird after I closed the
window.

Could you explain me what is going on and what should I look into for
understanding how to solve the issue?

[]'s
Rafael
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Sometimes I wish there was a global variable

2009-03-21 Thread Rafael Cunha de Almeida
Hello,

I am writing a OpenGL program in haskell, it can be found in:
http://github.com/aflag/galo/tree/master
But I hope this e-mail will be self-contained :).

My main function goes like this:
(...)
rotX - newIORef (0.0::GLfloat)
rotY - newIORef (0.0::GLfloat)
pos - newIORef (0.0::GLfloat, 0.0, 0.0)

displayCallback $= display (map f range) rotX rotY pos

keyboardMouseCallback $= Just (keyboardMouse rotX rotY pos)
(...)

Notice that rotX, rotY and pos are meant to be used as comunication
between the keyboardMouse and display functions. They need to be set as
0 first, so display won't do anything. Only when they user press a few
buttons that those values change, so display behaves accordanly.

In a state-based language I would place display and keyboardMouse in one
module and let them communcate to each other like they want. In haskell,
I'm not quite sure how to do it except by that parameter passing style.

I thought about how state-monad may help with that. But I'm not sure how
I'd make the state variable to be contained inside a
display/keyboardMouse module.

[]'s
Rafael
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Interesting problem from Bird (4.2.13)

2009-03-04 Thread Rafael Gustavo da Cunha Pereira Pinto
Mine is somewhat more elegant...


data (CatList a)   =  CatNil
   |  Wrap a
   |  Cat (CatList a) (CatList a) deriving Show


instance (Eq a) = Eq (CatList a) where
   CatNil  == CatNil = True
   Wrap x  == Wrap y = x==y

   a@(Cat x y) == b  = case (adjust a) of
  CatNil  - b==CatNil
  Wrap x  - (adjust b)==Wrap x
  Cat x y -
 case (adjust b) of
   Cat z w   - (x==z)  (y==w)
   otherwise - False

   b == a@(Cat x y) = a==b
   _ == _ = False

adjust   :: CatList a - CatList a
adjust (Cat CatNil x) = x
adjust (Cat x CatNil) = x
adjust (Cat (Cat x y) z) = adjust (Cat x (Cat y z))
adjust (Cat x y) = Cat (adjust x) (adjust y)
adjust x = x


You don't have to evaluate everything. Just do a recursion fixing the
associative rule.



2009/3/4 R J rj248...@hotmail.com

  Could someone provide an elegant solution to Bird problem 4.2.13?

 Here are the problem and my inelegant solution:

 Problem
 ---

 Since concatenation seems such a basic operation on lists, we can try to
 construct a data type that captures
 concatenation as a primitive.

 For example,

 data (CatList a)   =  CatNil
|  Wrap a
|  Cat (CatList a) (CatList a)

 The intention is that CatNil represents [], Wrap x represents [x], and Cat
 x y represents
 x ++ y.

 However, since ++ is associative, the expressions Cat xs (Cat ys zs)
 and Cat (Cat xs ys) zs should be regarded as equal.

 Define appropriate instances of Eq and Ord for CatList.

 Inelegant Solution
 --

 The following solution works:

 instance (Eq a) = Eq (CatList a) where
 CatNil  ==  CatNil   =True
 CatNil  ==  Wrap   z =False
 CatNil  ==  Catz w   =  ( z == CatNil   w == CatNil )

 Wrap   x==  CatNil   =False
 Wrap   x==  Wrap   z =x == z
 Wrap   x==  Catz w   =  ( Wrap x == z   w == CatNil ) ||
 ( Wrap x == w   z == CatNil )

 Catx y  ==  CatNil   =x == CatNil   y == CatNil
 Catx y  ==  Wrap   z =  ( x == Wrap z   y == CatNil ) ||
 ( x == CatNil   y == Wrap z )
 Catx y  ==  Catz w   =  unwrap (Cat x y) == unwrap (Cat z w)

 unwrap   :: CatList a - [a]
 unwrap CatNil=  []
 unwrap (Wrap x)  =  [x]
 unwrap (Cat x y) =  unwrap x ++ unwrap y

 instance (Eq a, Ord a) = Ord (CatList a) where
 x  y = unwrap x  unwrap y

 This solution correctly recognizes the equality of the following, including
 nested lists(represented, for example, by Wrap (Wrap 1), which corresponds
 to [[1]]):

 Wrap 1   == Cat (Wrap 1) CatNil
 Cat (Wrap 1) (Cat (Wrap 2) (Wrap 3)) == Cat (Wrap 1) (Cat (Wrap 2) (Wrap
 3))
 Wrap (Wrap 1)== Wrap (Cat (Wrap 1) CatNil)

 Although this solution works, it's a hack, because unwrap converts CatLists
 to lists.  The question clearly seeks a pure solution that does not rely
 on Haskell's built-in lists.

 What's the pure solution that uses cases and recursion on
 CatList, not Haskell's built-in lists, to capture the equality of nested
 CatLists?


 --
 Windows Live™ Contacts: Organize your contact list. Check it 
 out.http://windowslive.com/connect/post/marcusatmicrosoft.spaces.live.com-Blog-cns%21503D1D86EBB2B53C%212285.entry?ocid=TXT_TAGLM_WL_UGC_Contacts_032009

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




-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Interesting problem from Bird (4.2.13)

2009-03-04 Thread Rafael Gustavo da Cunha Pereira Pinto
Good point Ryan,

I did it in my lunch time and, being in a hurry, overlooked the fact that
left adjust in (*2) is redundant and that (*1) can be completely removed by
using (adjust x). I actually think I added (*2) for safety!! :-D

R J, you should take a look on Chris Okasaki's book. This is pretty much
what he does all the time to make sure invariants in his data structures are
met.

Best Regards,

Rafael

On Wed, Mar 4, 2009 at 15:55, Ryan Ingram ryani.s...@gmail.com wrote:

 2009/3/4 R J rj248...@hotmail.com:
  What's the pure solution that uses cases and recursion on
  CatList, not Haskell's built-in lists, to capture the equality of nested
  CatLists?

 As Rafael pointed out, the simplest thing to do is to convert to a
 canonical form; you can prove that each CatList has a single canonical
 form and that two equal CatLists always have the same canonical form.

 Something from Rafael's solution was bugging me, though.
  adjust   :: CatList a - CatList a
  adjust (Cat CatNil x) = x
  adjust (Cat x CatNil) = x -- *1
  adjust (Cat (Cat x y) z) = adjust (Cat x (Cat y z))
  adjust (Cat x y) = Cat (adjust x) (adjust y)  -- *2
  adjust x = x

 *2 is the more odd one.  I was sure he had missed a case where the
 result of the left adjust was incorrect.  But he didn't; the
 interesting thing is that the left adjust is redundant.  The only case
 left is Wrap which does nothing.

 *1 is a bit odd because it breaks the nice symmetry of the
 pattern-matching.

 Also, the CatNil cases both fail to adjust the results.

 Here's my solution:

  canonical (Cat CatNil xs) = canonical xs
  canonical (Cat (Cat x y) z) = canonical (Cat x (Cat y z))
  canonical (Cat x xs) = Cat x (canonical xs) -- x is Wrap e for some e
  canonical (Wrap e) = Cat (Wrap e) CatNil
  canonical CatNil = CatNil

 However, this is basically just converting to a list!  In canonical
 form, a CatList always looks like this:

 Cat (Wrap e1) $ Cat (Wrap e2) $ Cat (Wrap e3) $ ... $ CatNil

  canon_eq CatNil CatNil = True
  canon_eq (Cat (Wrap x) xs) (Cat (Wrap y) ys) = x == y  canon_eq xs ys
  canon_eq _ _ = False

  instance Eq a = Eq (CatList a) where xs == ys = canonical xs `canon_eq`
 canonical ys

 Gleb's viewCL solution is also interesting, but it is also
 equivalent to using lists, due to lazy evaluation.  In fact, an
 efficient toList on CatLists is just unfoldr viewCL.
 ___
 Haskell-Cafe mailing list
 Haskell-Cafe@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell-cafe




-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Purely funcional LU decomposition

2009-02-05 Thread Rafael Gustavo da Cunha Pereira Pinto
2009/2/5 Henning Thielemann lemm...@henning-thielemann.de



 -- Forwarded message --
 From: Henning Thielemann thunderb...@henning-thielemann.de
 To: Rafael Gustavo da Cunha Pereira Pinto rafaelgcpp.li...@gmail.com
 Date: Thu, 05 Feb 2009 14:43:13 +0100
 Subject: Re: [Haskell-cafe] Purely funcional LU decomposition
 Rafael Gustavo da Cunha Pereira Pinto wrote:


interesting to look at real matrix code that people have written and
think about what would be needed in a library to make it easier to
write.
--
Dan


 What I miss most is a data structure with O(1) (amortized) direct access.


 STArray and STUArray?



Are they? :-)



-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Purely funcional LU decomposition

2009-02-05 Thread Rafael Gustavo da Cunha Pereira Pinto
On Wed, Feb 4, 2009 at 05:15, Neal Alexander wqeqwe...@hotmail.com wrote:

 Array is no good man! Quad Tree matrices perform much nicer from what I've
 seen.

 I wrote some matrix stuff based on D. Stott Parker's Randomized Gaussian
 elimination papers 
 (http://www.cs.ucla.edu/~stott/ge/http://www.cs.ucla.edu/%7Estott/ge/).
 He presents some recursive block based methods of solving without pivoting.

 I want to upload the full library to Hackage, but it'd be nice to have some
 people look through it before - mainly because i never took linear algebra
 heh. QuickCheck seems to be holding things together though.



I read some of those papers and, yes, it is impressive. OTOH, I really need
pivoting (some ill-conditioned matrices are expected), which they all claim
to be hard to implement using quadtrees and I'm afraid that using RBTs might
introduce other sources of error.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Purely funcional LU decomposition

2009-02-04 Thread Rafael Gustavo da Cunha Pereira Pinto
On Wed, Feb 4, 2009 at 04:42, Thomas Davie tom.da...@gmail.com wrote:


 Shinyness indeed – a quick note though, as ghc doesn't support dynamic
 linking of Haskell code, the above is equivalent to the GPL.


I always use LGPL. Anyway, I will keep it that way, as I still have hopes on
dynamic linking Haskell  becoming a reality



 Would be lovely if you packaged this up and stuck it on Hackage :)


I may do that when I am finished with all the other stuff. I am building a
(very primitive) circuit simulator using Haskell.

It is a toy I am doing just to learn Haskell (until now I learned how to use
Arrays and Parsec)...




 Bob




-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Purely funcional LU decomposition

2009-02-04 Thread Rafael Gustavo da Cunha Pereira Pinto
Matt's code is pretty comprehensive.

His LU implementation is much cleaner, essentially  because he used the
ijk format, while I used the kij.

I'll take a look and e-mail him eventually.

Thanks!



On Tue, Feb 3, 2009 at 23:26, Paulo Tanimoto tanim...@arizona.edu wrote:

 Hi Rafael,

 2009/2/3 Rafael Gustavo da Cunha Pereira Pinto rafaelgcpp.li...@gmail.com
 :
 
Hello folks
 
 
   After a discussion on whether is possible to compile hmatrix in
  Windows, I decided to go crazy and do a LU decomposition entirely in
  Haskell...
 
   At first I thought it would be necessary to use a mutable or
  monadic version of Array, but then I figured out it is a purely
 interactive
  process.
 
   I am releasing this code fragment as LGPL.
 

 Pretty cool, thanks for releasing this into the wild.  I remember
 looking into this about a year ago.  By the way, have you seen Matt's
 DSP library?

 http://haskelldsp.sourceforge.net/

 He's got LU and others in there, if my memory serves me.  The last
 release seems to be 2003, so it might be worth emailing him to see
 what happened and if he has plans for the future.

 Regards,

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




-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Purely funcional LU decomposition

2009-02-04 Thread Rafael Gustavo da Cunha Pereira Pinto
On Wed, Feb 4, 2009 at 17:09, Dan Piponi dpip...@gmail.com wrote:

 2009/2/3 Rafael Gustavo da Cunha Pereira Pinto rafaelgcpp.li...@gmail.com
 :
   After a discussion on whether is possible to compile hmatrix in
  Windows, I decided to go crazy and do a LU decomposition entirely in
  Haskell...
  import Data.Array.IArray
 ...
e_an i j=a!(i,j)-(lik i)*a!(k,j)

 There are three different representations of arrays in this code:
 arrays, lists and a functional one where f represents an array with
 elements (f i j). Looks like a candidate for a stream fusion type
 thing so the user only writes code using one representation and some
 RULES switch back and forth between representations behind the scenes.
 --
 Dan


Those different representations are derived from my (very) low Haskell
handicap! :-D

1) I used lists for the intermediate L and U matrices so I wouldn't have the
overhead of calling accumArray and assocs everywhere
2) I used the function that returns an array element just to shorten the
line length, and to make sure I was typing it right!

When I started this, I thought I would end with a couple of folds, but then
I turned to the recursive version, so I could implement pivoting on matrix
a' more easily.

List comprehension also derived from this. I started thinking of a fold for
L matrix and then it hit me that it was a list comprehension...

Matt's DSP library has one of the most elegant implementations I saw, but it
is harder to implement pivoting, which is really important for my
application.

lu :: Array (Int,Int) Double -- ^ A
   - Array (Int,Int) Double -- ^ LU(A)

lu a = a'
where a' = array bnds [ ((i,j), luij i j) | (i,j) - range bnds ]
  luij i j | ij  = (a!(i,j) - sum [ a'!(i,k) * a'!(k,j) | k - [1
..(j-1)] ]) / a'!(j,j)
   | i=j =  a!(i,j) - sum [ a'!(i,k) * a'!(k,j) | k - [1 
..(i-1)] ]
  bnds = bounds a



-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Purely funcional LU decomposition

2009-02-04 Thread Rafael Gustavo da Cunha Pereira Pinto
On Wed, Feb 4, 2009 at 19:14, Dan Piponi dpip...@gmail.com wrote:

 On Wed, Feb 4, 2009 at 12:57 PM, Rafael Gustavo da Cunha Pereira Pinto
 rafaelgcpp.li...@gmail.com wrote:

  Those different representations are derived from my (very) low Haskell
  handicap! :-D

 BTW That wasn't intended in any way as a criticism. I think it's


Not taken!



 interesting to look at real matrix code that people have written and
 think about what would be needed in a library to make it easier to
 write.
 --
 Dan


What I miss most is a data structure with O(1) (amortized) direct access.

One of the changes I thought today was to remove the ++ operator and create
a list of lists that I would concat in the last call.

-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Purely funcional LU decomposition

2009-02-03 Thread Rafael Gustavo da Cunha Pereira Pinto
  Hello folks


 After a discussion on whether is possible to compile hmatrix in
Windows, I decided to go crazy and do a LU decomposition entirely in
Haskell...

 At first I thought it would be necessary to use a mutable or
monadic version of Array, but then I figured out it is a purely interactive
process.

 I am releasing this code fragment as LGPL.

{-
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see http://www.gnu.org/licenses/.

-}

import Data.Array.IArray

type Dim=(Int,Int)

lu::Array Dim Double - (Array Dim Double,Array Dim Double)
lu a = (aa l,aa u)
  where
  (l,u)=lu' a [] []
  aa = accumArray (+) 0 (bounds a)
  lu'::(Floating e) = Array Dim e - [(Dim,e)] - [(Dim,e)] -
([(Dim,e)],[(Dim,e)])
  lu' a l u=if (ui==li) then (
((ui,uj),1.0):l,((ui,uj),a!(ui,uj)):u) else (lu' an (l++ln) (u++un))
where
  k=li
  ((li,lj),(ui,uj))=bounds a
  lik i=(a!(i,k)/a!(k,k))
  un=[((k,j),a!(k,j)) | j-[lj..uj]]
  ln=((lj,lj),1.0):[((i,k),lik i) | i-[li+1..ui]]
  an=array ((li+1,lj+1),(ui,uj)) [((i,j),e_an i j) |
i-[li+1..ui],j-[lj+1..uj]]
  e_an i j=a!(i,j)-(lik i)*a!(k,j)



  Still needed:

1) Partial pivoting
2) Profiling... Lots!
3) Parallelize


-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] hmatrix, Windows and GCC

2009-01-28 Thread Rafael Gustavo da Cunha Pereira Pinto
I was planning to recompile everything (ATLAS, LAPACK and GHC included) this
weekend, so I can have a similar environment on Windows and Linux... Having
to borrow libraries

Since I am married, this means it will actually happen on some weekend till
2010.


What I really would like to try is a (purely?) functional approach to create
a (P)LU decomposition of a matrix. I am not too much worried (at first) with
performance or memory constraints, since I only want to see how beautiful it
gets (or not!).  (This one might happen somewhere in this century...)


Thanks anyway


On Wed, Jan 28, 2009 at 07:57, allan a.d.cl...@ed.ac.uk wrote:

 Hi

 The INSTALL file in the hmatrix repository has some very clear instructions
 for installation on Windows.
 http://perception.inf.um.es/~aruiz/darcs/hmatrix/INSTALLhttp://perception.inf.um.es/%7Earuiz/darcs/hmatrix/INSTALL

 However note this section at the bottom:
 Unfortunately the lapack dll supplied by the R system does not include
 zgels_, zgelss_, and zgees_, so the functions depending on them
 (linearSolveLS, linearSolveSVD, and schur for complex data)
 will produce a non supported in this OS runtime error.

 Of course linearSolve is exactly what you will be wanting so this won't
 work for you.
 I ran into exactly this problem myself. I actually didn't get as far as a
 run-time error as I got a linker error.

 I don't have any solution for you though, sorry.

 regards
 allan




 Rafael Gustavo da Cunha Pereira Pinto wrote:



   Hi all,

 I am writing a program that uses hmatrix for solving some linear systems.
 The hmatrix package depends on BLAS, which, in turn, depend on GCC 4.2 to be
 built (at least ATLAS does).

 GHC 6.10 for Windows is pre-packaged with GCC 3.4.5, and it leaves me with
 the impression that I would have incompatible ABIs.

 My questions:

 1) Why GHC 6.10 still uses GCC 3.4.5 in Windows? I know mingw considers
 GCC 4.2 to be alpha, but, lets face it, 4.2 is almost obsolete!
 2) Is it possible to rebuild GHC 6.10, using Windows and GCC 4.2? Is there
 any guide for doing this?
 3) Has any of you tried hmatrix on Windows? How did you do it?

 Thanks,

 Rafael

 --
 Rafael Gustavo da Cunha Pereira Pinto
 Electronic Engineer, MSc.


 

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




 --
 The University of Edinburgh is a charitable body, registered in
 Scotland, with registration number SC005336.




-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] hmatrix, Windows and GCC

2009-01-28 Thread Rafael Gustavo da Cunha Pereira Pinto
Well, I guess I am not the only one!

This blog show exactly what I am looking for!

http://quantile95.com/2008/10/31/ann-blas-bindings-for-haskell-version-06/



On Wed, Jan 28, 2009 at 08:21, Rafael Gustavo da Cunha Pereira Pinto 
rafaelgcpp.li...@gmail.com wrote:

 I was planning to recompile everything (ATLAS, LAPACK and GHC included)
 this weekend, so I can have a similar environment on Windows and Linux...
 Having to borrow libraries

 Since I am married, this means it will actually happen on some weekend till
 2010.


 What I really would like to try is a (purely?) functional approach to
 create a (P)LU decomposition of a matrix. I am not too much worried (at
 first) with performance or memory constraints, since I only want to see how
 beautiful it gets (or not!).  (This one might happen somewhere in this
 century...)


 Thanks anyway



 On Wed, Jan 28, 2009 at 07:57, allan a.d.cl...@ed.ac.uk wrote:

 Hi

 The INSTALL file in the hmatrix repository has some very clear
 instructions for installation on Windows.
 http://perception.inf.um.es/~aruiz/darcs/hmatrix/INSTALLhttp://perception.inf.um.es/%7Earuiz/darcs/hmatrix/INSTALL

 However note this section at the bottom:
 Unfortunately the lapack dll supplied by the R system does not include
 zgels_, zgelss_, and zgees_, so the functions depending on them
 (linearSolveLS, linearSolveSVD, and schur for complex data)
 will produce a non supported in this OS runtime error.

 Of course linearSolve is exactly what you will be wanting so this won't
 work for you.
 I ran into exactly this problem myself. I actually didn't get as far as a
 run-time error as I got a linker error.

 I don't have any solution for you though, sorry.

 regards
 allan




 Rafael Gustavo da Cunha Pereira Pinto wrote:



   Hi all,

 I am writing a program that uses hmatrix for solving some linear systems.
 The hmatrix package depends on BLAS, which, in turn, depend on GCC 4.2 to be
 built (at least ATLAS does).

 GHC 6.10 for Windows is pre-packaged with GCC 3.4.5, and it leaves me
 with the impression that I would have incompatible ABIs.

 My questions:

 1) Why GHC 6.10 still uses GCC 3.4.5 in Windows? I know mingw considers
 GCC 4.2 to be alpha, but, lets face it, 4.2 is almost obsolete!
 2) Is it possible to rebuild GHC 6.10, using Windows and GCC 4.2? Is
 there any guide for doing this?
 3) Has any of you tried hmatrix on Windows? How did you do it?

 Thanks,

 Rafael

 --
 Rafael Gustavo da Cunha Pereira Pinto
 Electronic Engineer, MSc.


 

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




 --
 The University of Edinburgh is a charitable body, registered in
 Scotland, with registration number SC005336.




 --
 Rafael Gustavo da Cunha Pereira Pinto
 Electronic Engineer, MSc.




-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] hmatrix, Windows and GCC

2009-01-27 Thread Rafael Gustavo da Cunha Pereira Pinto
   Hi all,

I am writing a program that uses hmatrix for solving some linear systems.
The hmatrix package depends on BLAS, which, in turn, depend on GCC 4.2 to be
built (at least ATLAS does).

GHC 6.10 for Windows is pre-packaged with GCC 3.4.5, and it leaves me with
the impression that I would have incompatible ABIs.

My questions:

1) Why GHC 6.10 still uses GCC 3.4.5 in Windows? I know mingw considers GCC
4.2 to be alpha, but, lets face it, 4.2 is almost obsolete!
2) Is it possible to rebuild GHC 6.10, using Windows and GCC 4.2? Is there
any guide for doing this?
3) Has any of you tried hmatrix on Windows? How did you do it?

Thanks,

Rafael

-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] How outdated is Hugs?

2009-01-27 Thread Rafael Gustavo da Cunha Pereira Pinto
Hi,

I see Hugs last source code snapshot dates back to 2006. Was there any
updates?

Regards


-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: The problem with Monads...

2009-01-14 Thread Rafael Gustavo da Cunha Pereira Pinto
Wadler's examples are way better than the ones in the documentation. But
without his explanations of what he is doing, the examples alone are pretty
worthless.

I agree that all_about_monads could be a better source for the
documentation, at least for completeness. But even there I would consider
choosing simpler examples, like Wadler's expression evaluator.




On Tue, Jan 13, 2009 at 21:07, Benedikt Huber benj...@gmx.net wrote:

 Rafael Gustavo da Cunha Pereira Pinto schrieb:

 Yes, I've read it twice, and it is a nice explanation that yes, the
 reader monad is an application and is a monad. How do I use it? Why not the
 function itself? How would the plumbing work in a real world example?

 Hi Rafael,

 First of all, I agree that the documentation for mtl should be improved.
 Especially Control.Monad.RWS and Control.Monad.List really need some more
 information.

 The documentation for the Reader and Identity monad are quite detailled
 though. They seem to be inspired by
 http://www.haskell.org/all_about_monads/, which also has documentation on
 Writer and Cont.

 Control.Monad.List is a good example for the lack of documentation:
 There is a single sentence at the beginning
  The List monad.
 and then one declaration
  newtype ListT m a = ListT { runListT :: m [a] }
 while the important information is hidden as one of many instance
 declarations:
  Monad m = Functor (ListT m)
  Monad m = MonadPlus (ListT m)

 Btw, the quality of the examples in Control.Monad.Reader is debutable. From
 Example 1:

  -- The Reader monad, which implements this complicated check.
  calc_isCountCorrect :: Reader Bindings Bool
  calc_isCountCorrect = do
 count - asks (lookupVar count)
 bindings - ask
 return (count == (Map.size bindings))

 I think it is wrong (or weird at least) to call the function a 'Reader
 monad'; the name 'calc_isCountCorrect' is horrible too (because of the calc_
 prefix),  Finally, implementing

  isCountCorrect :: Bindings - Bool
  isCountCorrect bs = (bs Map.! count) == Map.size bs

 using the Reader monad will convince everybody _not_ to use it.

 A suggestion: If license permits it, short versions of the articles on
 all_about_monads would make a great documentation for mtl (except for RWS
 and List, which are missing).

 benedikt



 BTW, the article is really great as an brief introduction to monad
 transformers. For the whole concept of monads, my all time favorite is The
 Haskell Programmer's Guide to the IO Monad by Stefan Klinger.

 Chapters 14 to 19 of Real World Haskell also have a good introduction on
 the usage of the monads, but it lacks other monads, like the RWS or the
 Continuation...

 See, that is my point. The mathematical concept of monads is very
 palatable. The idea that monads are either patterns or structures to hide
 computations in sequence is also very easy to see. But how do we use them?
 Why should I use a Writer monad when I can use a (a,w) tuple?



 On Tue, Jan 13, 2009 at 13:51, Jonathan Cast 
 jonathancc...@fastmail.fmmailto:
 jonathancc...@fastmail.fm wrote:

On Tue, 2009-01-13 at 12:56 -0200, Rafael Gustavo da Cunha Pereira
 Pinto
wrote:
 
  Last night I was thinking on what makes monads so hard to take, and
  came to a conclusion: the lack of a guided tour on the implemented
  monads.

...

  Inspired by the paper Functional Programming with Overloading and
  Higher-Order Polymorphism,
  Mark P Jones
  
 (http://web.cecs.pdx.edu/~mpj/pubs/springschool.htmlhttp://web.cecs.pdx.edu/%7Empj/pubs/springschool.html
http://web.cecs.pdx.edu/%7Empj/pubs/springschool.html)
Advanced School of Functional Programming, 1995.
 
  SO WHAT?

So have you read Jones' paper?  Or do you have a *concrete* explanation
of how it differs from your desired `guided tour'?

jcc





 --
 Rafael Gustavo da Cunha Pereira Pinto
 Electronic Engineer, MSc.


 

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





-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] The problem with Monads...

2009-01-13 Thread Rafael Gustavo da Cunha Pereira Pinto
Last night I was thinking on what makes monads so hard to take, and came to
a conclusion: the lack of a guided tour on the implemented monads.

Let's take the Writer monad documentation: all it says is:

Inspired by the paper Functional Programming with Overloading and
Higher-Order Polymorphism,
Mark P Jones (http://web.cecs.pdx.edu/~mpj/pubs/springschool.html)
  Advanced School of Functional Programming, 1995.

SO WHAT?

The best approach is the Part II of the All About Monads tutorial. There
you have the almost ideal approach, except that the examples are just thrown
there, with no step-by-step explanation.

Of course one could copy, paste and run it, but this gives pretty much a is
it right?'  feeling. Questions like if a Reader is an application, why
don't use a regular function instead? or what bind means for a State
monad?.

I will try to work on a Part II extended version on my vacations... maybe
a WikiMonad... or MonadPedia... :-)

After all, it is my duty as a haskell noob to write another monad tutorial!
:D

Cheers!

-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] The problem with Monads...

2009-01-13 Thread Rafael Gustavo da Cunha Pereira Pinto
Yes, I've read it twice, and it is a nice explanation that yes, the reader
monad is an application and is a monad. How do I use it? Why not the
function itself? How would the plumbing work in a real world example?

BTW, the article is really great as an brief introduction to monad
transformers. For the whole concept of monads, my all time favorite is The
Haskell Programmer's Guide to the IO Monad by Stefan Klinger.

Chapters 14 to 19 of Real World Haskell also have a good introduction on
the usage of the monads, but it lacks other monads, like the RWS or the
Continuation...

See, that is my point. The mathematical concept of monads is very palatable.
The idea that monads are either patterns or structures to hide computations
in sequence is also very easy to see. But how do we use them?
Why should I use a Writer monad when I can use a (a,w) tuple?



On Tue, Jan 13, 2009 at 13:51, Jonathan Cast jonathancc...@fastmail.fmwrote:

 On Tue, 2009-01-13 at 12:56 -0200, Rafael Gustavo da Cunha Pereira Pinto
 wrote:
 
  Last night I was thinking on what makes monads so hard to take, and
  came to a conclusion: the lack of a guided tour on the implemented
  monads.

 ...

  Inspired by the paper Functional Programming with Overloading and
  Higher-Order Polymorphism,
  Mark P Jones
  (http://web.cecs.pdx.edu/~mpj/pubs/springschool.htmlhttp://web.cecs.pdx.edu/%7Empj/pubs/springschool.html
 )
Advanced School of Functional Programming, 1995.
 
  SO WHAT?

 So have you read Jones' paper?  Or do you have a *concrete* explanation
 of how it differs from your desired `guided tour'?

 jcc





-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] The problem with Monads...

2009-01-13 Thread Rafael Gustavo da Cunha Pereira Pinto
I didn't knew Wadler's papers (I save all papers I read into a external USB
HD, so I can read them later!), and at a first glance it is really good.


Then again, instead of creating another monad tutorial, what about a
Haskell monads reference guide, and some worked examples?

Some of this work could even be attached to the library documentation.

Regards

Rafael


On Tue, Jan 13, 2009 at 15:27, Derek Elkins derek.a.elk...@gmail.comwrote:

 On Tue, 2009-01-13 at 16:22 +, Sittampalam, Ganesh wrote:
  Jonathan Cast wrote:
   On Tue, 2009-01-13 at 12:56 -0200, Rafael Gustavo da Cunha Pereira
   Pinto wrote:
  
   Inspired by the paper Functional Programming with Overloading and
   Higher-Order Polymorphism, Mark P Jones
   (http://web.cecs.pdx.edu/~mpj/pubs/springschool.htmlhttp://web.cecs.pdx.edu/%7Empj/pubs/springschool.html
 )
 Advanced School of Functional Programming, 1995.
  
   SO WHAT?
  
   So have you read Jones' paper?  Or do you have a *concrete*
   explanation of how it differs from your desired `guided tour'?
 
  To give a specific example, a few weeks ago I wanted an explanation of
  the 'pass' function and couldn't find it in that paper.
 
  Ganesh

 Several years ago I documented all the (basic) monads in the mtl on the
 (old) wiki.

 http://web.archive.org/web/20030927210146/haskell.org/hawiki/MonadTemplateLibrary
 In particular,
 http://web.archive.org/web/20030907203223/haskell.org/hawiki/MonadWriter


 To respond to the essential point of Rafael's initial claim, Wadler's
 papers The Essence of Functional Programming and/or Monads for
 Functional Programming have exactly what he wants.  These are the
 papers that I recommend to anyone who is learning about monads.
 http://homepages.inf.ed.ac.uk/wadler/topics/monads.html

 Please, we do not need the 101st monad tutorial when there was an
 adequate one made almost two decades ago.  While I'm not saying that
 this is the case here, I suspect that many people don't read those
 papers because 1) they haven't heard of them and 2) they are papers
 and thus couldn't possibly be readable and understandable (which also
 partially causes (1) as people just don't think to look for papers at
 all.)




-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell participating in big science like CERN Hadrian...

2008-10-03 Thread Rafael Gustavo da Cunha Pereira Pinto



 On Fri, Oct 3, 2008 at 07:47, Dougal Stanton [EMAIL PROTECTED]wrote:

 2008/10/3 Galchin, Vasili [EMAIL PROTECTED]:
  Hello,
 
  One of my interests based on my education is grand challenge
 science.
  Ok .. let's take the  CERN Hadrian Accelerator.
 
  Where do you think Haskell can fit into the CERN Hadrian effort
  currently?
 
  Where do you think think Haskell currently is lacking and will have
 to
  be improved in order to participate in CERN Hadrian?

 Is that the experiment where Picts are accelerated to just short of
 the speed of light in order to smash through to the Roman Empire? ;-)




Man, that was almost as good as the Large Hardon
Colliderhttp://largehardoncollider.com/
!!!



 I don't know what the main computational challenges are to the LHC
 researchers. The stuff in the press has mostly been about
 infrastructure --- how to store the gigabytes of data per second that
 they end up keeping, out of the petabytes that are produced in the
 first place (or something).




There is a lot of data filtering, looking for the right trigger event...

-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Kind-of-off-Topic: Random thoughts on language design

2008-09-26 Thread Rafael Gustavo da Cunha Pereira Pinto
Hi all,

 TGIF! And since it is friday, I started thinking on some alternatives
to program PIC processors...

  I don't know how many of you are familiar with the PIC family of
microcontrollers http://www.microchip.com/. They are RISC controllers with
a wide range of complexity, starting on 8-bit and up to 32-bit, but the
architecture is basically the same:


   - RISC
   - Register based (from 20-16k general purpose registers)
   - Limited hardware call stack.

  While studying Haskell, the functional bug bit me and I realized that
this architecture is somewhat not well suited for traditional compilers. I
suddenly started thinking on how one could implement some kind of
declarative language that could easy the programming of those beasts.

  One of the approaches I thought was to use a block based programming
(like Simulink), defining atomic operations that would be wired together.

  Do you think a compiler for this block language could this be
implemented in Haskell? What about using the Arrow monads?

  Best Regards

-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: [Haskell] ICFP programming contest results

2008-09-24 Thread Rafael Gustavo da Cunha Pereira Pinto
Is the report available yet?

Regards

On Wed, Sep 24, 2008 at 13:06, Don Stewart [EMAIL PROTECTED] wrote:

 daveroundy:
  On Wed, Sep 24, 2008 at 1:06 AM, Malcolm Wallace
  [EMAIL PROTECTED] wrote:
   The ICFP programming contest results presentation:
   http://video.google.com/videoplay?docid=-4697764813432201693
  
   Feel free to pass on this link to any other appropriate forum.
 
  Yikes.  Haskell did pretty terribly! Anyone have an idea why, given
  our success in previous contests?
 
  David (speaking as someone who was traveling that weekend and didn't
  have time to compete)

 I would say we did OK,

 Top 10:
Java, C++, Java, Haskell, Haskell, C , C++ , C , C++, C++

 So now given the size of the competition, the results are starting to
 look more like places like topcoder or spoj, where the top entries are
 primarily C and C++, but with a disproportionate represenation of
 Haskell and OCaml at the top end.

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




-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Haskell board game

2008-09-24 Thread Rafael C. de Almeida
Hello,

I'm interested in doing a simple board game on haskell. For that I want
to be able to draw stuff like the possible player movements and I want
to be able to display very simple animations. I want to know what
graphical interface library you suggest to me.

I have almost no prior experience with graphical interfaces of any kind,
so I rather start with something easy and straightforward. I have no
need for great performance or anything like that. I'd like if it runs on
windows with much trouble, that is, it'll be easy to package it for
windows without requiring the user to install anything besides my game.

My first thought was to use GTK's gtkTable, but I'm unsure how easy it
is to make it work on windows. Beside that, I'm not sure it would be the
 easiest API for me to use.

[]'s
Rafael
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Ropes

2008-09-22 Thread Rafael Gustavo da Cunha Pereira Pinto
That is a good idea!

If I implement head, tail, take drop operations, I can use my KMP
implementation out of the box...



On Sun, Sep 21, 2008 at 11:10, Nicolas Pouillard 
[EMAIL PROTECTED] wrote:

 Excerpts from Rafael Gustavo da Cunha Pereira Pinto's message of Sat Sep 20
 12:54:26 +0200 2008:
  I am doing the ICFPC07 task right now, to learn Haskell and tried to use
 the
  Sequence, but the final code is too damn slow (a few iterations per
  minute!).

 Is your structure a sequence of *Char*s, if so you should consider to use a
 sequence of strict bytestrings of a given size (chunks).

  The DNA needs only 2 operations: head (or take) and concat.
 
  I am thinking in using ropes for the DNA and sequences for all the rest
  (patterns, templates and RNA).
 
  On Fri, Sep 19, 2008 at 23:15, Ryan Ingram [EMAIL PROTECTED] wrote:
 
   I think Data.Sequence uses fingertrees which are pretty fast.
  
   I used a handgrown rope-like structure for ICFPC07 but I wish I had
   known about Sequence; it would have likely just been better.
  
-- ryan
  
   2008/9/19 Rafael Gustavo da Cunha Pereira Pinto 
   [EMAIL PROTECTED]:
Hi all,
   
Is there any implementation of the rope data structure in Haskell?
   
I couldn't find any on Hackage, and I am intending to implement it.
   
Regards,
   
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
   
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
   
   
  
 

 --
 Nicolas Pouillard aka Ertai




-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Fwd: [Haskell-cafe] hGetContents and lazyness

2008-09-22 Thread Rafael Gustavo da Cunha Pereira Pinto
-- Forwarded message --
From: Rafael Gustavo da Cunha Pereira Pinto [EMAIL PROTECTED]
Date: Mon, Sep 22, 2008 at 15:46
Subject: Re: [Haskell-cafe] hGetContents and lazyness
To: Max Vasin [EMAIL PROTECTED]


Why don't you use OpenFile?

 getPackageList packageFile = do
  h - OpenFile packageFile ReadMode
  c - hGetContents h
  return $ map (drop 10) $ filter (startsWith
Filename:) $ lines c

I am not at home so I don't have GHC around here, but this usually works for
me!

Anyway, it also depends on who is consuming the IO [FilePath] data returned.
It will not be evaluated unless asked for!


On Mon, Sep 22, 2008 at 14:52, Max Vasin [EMAIL PROTECTED] wrote:

 Hello, haskellers!

 Suppose we have function (it filters package filenames from apt Packages
 file):

  getPackageList :: FilePath - IO [FilePath]
  getPackageList packageFile = withFile packageFile ReadMode $
   \h - do c - hGetContents h
return $ map (drop 10) $ filter
 (startsWith Filename:) $ lines c -- (1)
  where startsWith [] _ = True
startsWith _ [] = False
startsWith (x:xs) (y:ys) | x == y= startsWith xs ys
 | otherwise = False

 When, I apply it to a Packages file I (surely) get an empty list. This is
 an expected result due to
 lazyness of hGetContents. I tried changing line (1) to

  return $ map (drop 10) $ filter (startsWith Filename:) $! lines c

 or

  return $ map (drop 10) $! filter (startsWith Filename:) $! lines c

 with no success.

 Chaning it to

  return $! map (drop 10) $ filter (startsWith Filename:) $ lines c

 makes getPackageList function return several (but not all) filenames.

 What I'm missing? And how can I fix my code?

 --
 WBR,
 Max Vasin.

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




-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.



-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Ropes

2008-09-20 Thread Rafael Gustavo da Cunha Pereira Pinto
On Fri, Sep 19, 2008 at 23:18, Don Stewart [EMAIL PROTECTED] wrote:

 RafaelGCPP.Linux:
 Hi all,
 
 Is there any implementation of the rope data structure in Haskell?
 
 I couldn't find any on Hackage, and I am intending to implement it.

 There's no mature rope implementation. Can you write a bytestring-rope
 that outperforms lazy bytestrings please :)


I'll give it a try, but cannot promise anything on the outperform part!
:-)

-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Ropes

2008-09-20 Thread Rafael Gustavo da Cunha Pereira Pinto
I am doing the ICFPC07 task right now, to learn Haskell and tried to use the
Sequence, but the final code is too damn slow (a few iterations per
minute!).

The DNA needs only 2 operations: head (or take) and concat.

I am thinking in using ropes for the DNA and sequences for all the rest
(patterns, templates and RNA).



On Fri, Sep 19, 2008 at 23:15, Ryan Ingram [EMAIL PROTECTED] wrote:

 I think Data.Sequence uses fingertrees which are pretty fast.

 I used a handgrown rope-like structure for ICFPC07 but I wish I had
 known about Sequence; it would have likely just been better.

  -- ryan

 2008/9/19 Rafael Gustavo da Cunha Pereira Pinto 
 [EMAIL PROTECTED]:
  Hi all,
 
  Is there any implementation of the rope data structure in Haskell?
 
  I couldn't find any on Hackage, and I am intending to implement it.
 
  Regards,
 
  Rafael Gustavo da Cunha Pereira Pinto
  Electronic Engineer, MSc.
 
  ___
  Haskell-Cafe mailing list
  Haskell-Cafe@haskell.org
  http://www.haskell.org/mailman/listinfo/haskell-cafe
 
 




-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Ropes

2008-09-20 Thread Rafael Gustavo da Cunha Pereira Pinto
I have been told that you could pretty much literally implement the
 algorithms
 from the problem specification with  Seq  from  Data.Sequence  and achieve
 acceptable speed (IIRC ~ one minute for generating a whole picture).


Yes, it is straightforward to implement the algorithm when using sequences.




 Are you sure that there is no unintentional bug in your implementation that
 slows things down?


The test cases on the problem definition all worked, but they touch very
little of the code.

I added some trace calls, but could not see any trouble. I also did some
runs by hand and it  seemed ok.

If only Gödel was wrong... :-)


-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.



-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Ropes

2008-09-19 Thread Rafael Gustavo da Cunha Pereira Pinto
Hi all,

Is there any implementation of the rope data structure in Haskell?

I couldn't find any on Hackage, and I am intending to implement it.

Regards,

Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Float instance of 'read'

2008-09-16 Thread Rafael C. de Almeida
Mauricio wrote:
 Hi,
 
 A small annoyance some users outside
 english speaking countries usually
 experiment when learning programming
 languages is that real numbers use
 a '.' instead of ','. Of course, that
 is not such a problem except for the
 inconsistence between computer and
 free hand notation.
 
 Do you think 'read' (actually,
 'readsPrec'?) could be made to also
 read the international convention
 (ie., read 1,5 would also work
 besides read 1.5)? I'm happy to
 finaly use a language where I can
 use words of my language to name
 variables, so I wonder if we could
 also make that step.
 

Isn't it locale dependent? If it isn't, it should be. Try setting your
locale right and see if things work. At least awk work fine that way.

Although I don't like too much that kinda stuff, I usually set the
locale to C so I keep all my programs behaving consistently. I have
problems with that stuff before (a file generated by an awk script had ,
instead of . and that would confuse other computers with a different
locale).
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell Weekly News: Issue 85 - September 13, 2008

2008-09-15 Thread Rafael C. de Almeida
Richard A. O'Keefe wrote:
 
 On 14 Sep 2008, at 10:59 pm, Rafael Almeida wrote:
 One thing have always bugged me: how do you prove that you have
 correctly proven something?
 
 This really misses the point of trying to formally verify something.
 That point is that you almost certainly have NOT.  By the time you
 get a theorem prover to accept your specification, you have
 (a) gone through a couple of rounds of redesign (before writing the
 code!) and now have something really clear (because the prover
 is too dumb to understand subtle stuff)
 (b) just done a lot of testing on the design that was finally
 accepted.
 
 I mean, when I write a code I'm formaly
 stating what I want to happen and bugs happen. If I try to prove some
 part of the code I write more formal text (which generally isn't even
 checked by a compiler);
 
 I'm sorry?
 What kind of half-arsed formal specification is NOT checked?
 None of the specification tools I've played with (I really wish there
 were a PVS course I could attend in NZ) can truthfully be described as
 not checked.

I do not know. I'm not experienced on the field and I was under the
impression you'd write your code then get a pen and a paper and try to
prove some property of it.

Someone mentioned coq, I read a bit about it, but it looked really
foreign to me. The idea is to somehow prove somethings based only on the
specification and, after that, you write your code, based on your proof?
If so, what's the difference of that and writing the same program twice
in two different languages? Isn't that kind of what's going on anyways?

 Symbolic model checking tools effectivley _are_ testing tools; what you
 normally get from them is not a cheery that's fine boss but a snarky
 you forgot about this possible input didn't you, idiot!

Do they operate with Haskell functions directly? I mean, can I somehow
import the functions I wrote in Haskell and try to prove properties on
it using those tools you talk about?

 how can I be sure that my proof doesn't
 contain bugs?
 
 You can't.  What you CAN be sure of is that your previous proof
 attempts DID contain bugs.  Lots of them.  At least *those* ones
 are gone.  Let's face it, you can't be *sure* that you aren't a brain
 in a jar being systematically deceived by a demon.  (Read Descartes.)
 
 In fact, you can usually be CERTAIN that you haven't proved the
 validity of your whole system, because you usually haven't tried.
 Formal methods are a risk reduction tool.  You pick some part of the
 system which has a special need for reliability, isolate it, model it,
 check the model for consistency, specify operations on it, prove
 something about them, and you learn a heck of a lot by doing so.
 What you can't eliminate is the possibility that something nasty is
 lurking in the BIOS of your computer specifically watching out for
 your code so it can sabotage it.  Several times in my programming
 career I have encountered perfectly correct code that malfunctioned
 because of a broken compiler (well ok, in one case it was a broken
 assembler).
 
 Why would it make my program less error-prone? Is there
 any article that tries to compare heavy testing with FM?
 
 Lots of them.
 http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.18.2475
 might make a good start.
 The idea that the FORTEST researchers share is that formal
 methods can *help* testing.
 Indeed, QuickCheck basically _is_ an 'automatic tests from
 specifications' tool, one of many that have been built over the
 years.
 
 If you stop thinking of formal methods as verifying finished
 written programs and more as some mix of design for
 checkability (so that bugs are less likely to be written into
 the code in the first place) or as testing for specifications
 it may make more sense to you.
 

Hm. I've used quickcheck, I find it really nice. It was definetely the
tool I had in mind when I was arguing about tests being enough to
'proof' things. Anyhow, I'll take a look on that article, maybe it
already answers lots of the questions I've raised here :-).
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell Weekly News: Issue 85 - September 13, 2008

2008-09-15 Thread Rafael Almeida
On Mon, Sep 15, 2008 at 2:43 PM, Robin Green [EMAIL PROTECTED] wrote:
 On Mon, 15 Sep 2008 13:05:11 -0300
 Rafael C. de Almeida [EMAIL PROTECTED] wrote:
 Someone mentioned coq, I read a bit about it, but it looked really
 foreign to me. The idea is to somehow prove somethings based only on
 the specification and, after that, you write your code, based on your
 proof?

 No. There are 3 main ways of using Coq:

 1. Code extraction. You write your code in Coq itself, prove that it
 meets your specification, and then use the Extraction commands to
 convert the Coq code into Haskell (throwing away all the proof bits,
 which aren't relevant at runtime).

 2. Verification condition generation (VCGen) - you write your code in
 some ordinary language, say Haskell, and annotate it with
 specifications. Then you run a VCGen tool over it and it tries to prove
 the trivial things, and spits out the rest as verification conditions
 in the language of Coq, ready to be proved in Coq.

That seemed to me the most interesting way of using it. After all, I
already like writing my programs in Haskell, not sure if I'd like Coq
better for programming. Also, that could work with code I've already
written. Do you know of a VCGen tool that works well with Haskell and
some other language such as Coq (doesn't need to be coq)? A quick
search on google didn't give me much.

 3. A combination of both of the above approaches - you write your code
 in Coq, ignoring the proof at first, and then verification conditions
 (called obligations in Coq) are generated. This is experimental. The
 commands that begin with Program in Coq are used for this.

 None of these involve writing the same code twice in different
 languages.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Should `(flip (^^))` work?

2008-09-15 Thread Rafael C. de Almeida
Derek Elkins wrote:
 On Mon, 2008-09-15 at 18:42 -0300, Mauricio wrote:
 Hi,

 I tested the expression below
 and it doesn't work. Is there
 some way to achieve that (i.e.,
 turning an expression inside
 parenthesis into an operator)?

 2 `(flip (^^))` (3%4)
 
 No it shouldn't work.  The fact that the opening and closing marks are the 
 same suggests that it shouldn't.  You can fake it though.
 
 x -| f = f x
 f |- x = f x
 
 2 -| flip (^^) |- (3%4)
 

Isn't naming the expression 'flip (^^)' much clearer?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Should `(flip (^^))` work?

2008-09-15 Thread Rafael Almeida
On Mon, Sep 15, 2008 at 8:09 PM, Mauricio [EMAIL PROTECTED] wrote:


 Rafael C. de Almeida a écrit :

 Derek Elkins wrote:

 On Mon, 2008-09-15 at 18:42 -0300, Mauricio wrote:

 Hi,

 I tested the expression below
 and it doesn't work. Is there
 some way to achieve that (i.e.,
 turning an expression inside
 parenthesis into an operator)?

 2 `(flip (^^))` (3%4)

 No it shouldn't work.  The fact that the opening and closing marks are
 the same suggests that it shouldn't.  You can fake it though.

 x -| f = f x
 f |- x = f x

 2 -| flip (^^) |- (3%4)


 Isn't naming the expression 'flip (^^)' much clearer?

 I think that is an interesting question
 about programming style. In practical
 code I think we should have a balance
 between the complexity of big expressions
 and the complexity of too many names.

Hm, I was suggesting a local name in a where or let clause. In my
experience, if there are too many local names it's evidence that you
should break up the function into other functions.

But what I'm saying is that I'd rather read something like: 2
`flippedPow` (3%4) then just check what flippedPow is on the where
clause than reading 2 -| flip (^^) |- (3%4) and having to figure out
what -| and |- do.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Haskell Weekly News: Issue 85 - September 13, 2008

2008-09-14 Thread Rafael Almeida
On Sun, Sep 14, 2008 at 5:56 AM, Thomas M. DuBuisson
[EMAIL PROTECTED] wrote:

 What would theorem proofs do for me?
 Imagine if you used SmallCheck to exhastively test the ENTIRE problem
 space for a given property.  Now imagine you used your brain to show the
 programs correctness before the heat death of the universe...

 Proofs are not features, nor are they code.  What you prove is entirely
 up to you and might not be what you think.  Take, for example, the issue
 of proving a sort function works correctly [1].

 I'm not saying this to discourage complete proofs, but just cautioning
 you that proving something as unimportant and IO laden as an IRC bot
 probably isn't the best example.  Do see the linked PDF, and [2] as
 well.

 Oh, and for examples where people should have used FM, search for
 'ariane 1996'  or the gulf war patriot missle failure

 TomMD

 [1]
 http://www.cl.cam.ac.uk/~mjcg/Teaching/SpecVer1/Lectures/pslides07x4.pdf
 [2] http://users.lava.net/~newsham/formal/reverse/


One thing have always bugged me: how do you prove that you have
correctly proven something? I mean, when I write a code I'm formaly
stating what I want to happen and bugs happen. If I try to prove some
part of the code I write more formal text (which generally isn't even
checked by a compiler); how can I be sure that my proof doesn't
contain bugs? Why would it make my program less error-prone? Is there
any article that tries to compare heavy testing with FM?
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Is there GHC 6.8.3 on Ubuntu?

2008-08-27 Thread Rafael Gustavo da Cunha Pereira Pinto
Is there anyone packing GHC 6.8.3 for Ubuntu Hardy?

Thanks


-- 
Rafael Gustavo da Cunha Pereira Pinto
Electronic Engineer, MSc.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Web processing

2008-08-02 Thread Rafael C. de Almeida
Hello,

I understand that nowadays there are several frameworks and wrapper
libraries for making some sense of the XHTML documents you find over the
web. That is, making the life of those who want to process the
semi-structured data you find on the sites.

I don't have much experience on that field myself, but I want to learn a
little more about how I can, for instance, associate information from
one site with information in another site. Even though it is structured
differently in both places. Does anyone know about libraries that would
help me out with that sort of work? Hope I'm being clear.

[]'s
Rafael
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Monad proof

2008-04-11 Thread Rafael C. de Almeida

Hello,

I was studying Monads and I was trying to think about new Monads I could 
 define. So, a question poped into my mind: how is proof regarding the 
3 Monad laws handled? I know that, aside from testing all the possible 
values (and there can be a lot of them), there's no general way to prove 
it. Nonetheless, I think that it would be insightful to see how people 
write those proofs for their monads -- specially for new user monads. Is 
there some article or some notes on proving that Monads are implemented 
correctly?


[]'s
Rafael
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Solving a geometry problem with Haskell

2008-01-13 Thread Rafael Almeida
On Sat, 12 Jan 2008 23:36:43 +0100, Daniel Fischer
[EMAIL PROTECTED] wrote:

 Am Samstag, 12. Januar 2008 22:48 schrieb Luke Palmer:
  On Jan 12, 2008 9:19 PM, Rafael Almeida [EMAIL PROTECTED] wrote:
   After some profiling I found out that about 94% of the execution time is
   spent in the ``isPerfectSquare'' function.
 
  That function is quite inefficient for large numbers.  You might try
  something like this:
 
  isPerfectSquare n  where
  searchSquare lo hi
 
| lo = hi| otherwise 
let midcase mid^2 `compare` n of
EQ - True
LT - searchSquare mid hi
GT - searchSquare lo mid
 
  Luke

 I don't want to be a spoil-sport, but that won't help much either. And
 although the logic of the programme is correct, the numbers involved are so
 large that I'd expect the running time to be rather years than days (it took
 a minute to solve for the smallest cathetus of 6 triangles, 128).
 Suppose the answer were 10^9 (it's much larger, actually). Then the limit for
 the other cathetus would be roughly 5*10^17 and for all these values it has
 to be checked whether n^2 + y^2 is a perfect square. If one check took a
 nanosecond, that would be roughly 5*10^8 seconds or nearly 16 years.
 Rafael, you have some good starts, but to get the answer in a reasonable time,
 you must employ some more algebra.
 Find a way to determine a cathetus of how many triangles a number is without
 actually constructing them is a good step.

 Cheers,
 Daniel


Now you really conviced me that the algorithm isn't right. Although I already
thought I needed to come up with a new algorithm when the GMP's perfect square
function didn't help. I thank for all the feedback on how to make
isPerfectSquare faster, though. It has been educational.

I'm trying to come up with something other than constructing the triangles, but
maybe I'm just not that strong at algebra. Thanks for de feedback, though.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: AW: [Haskell-cafe] Solving a geometry problem with Haskell

2008-01-13 Thread Rafael Almeida
On Sun, 13 Jan 2008 11:48:09 +0100, Nicu Ionita [EMAIL PROTECTED] wrote:

 Hi Rafael,

 I have just two ideas, that could improve your strategy to reduce the
 computation time:

 1. perhaps there is also a minimum (not only a maximul) for the values you
 should try

Yeah, that's a good one, the most I can narrow down the results the better. But
if I can figure out the number of triangles without actually constructing them
would be the real winner algorithm.


 2. is the function howManyTriangles monotone? If yes, then you could try to
 solve:

 howManyTriangles n = 47547

 by finding an upper n, nmax, where howManyTriangles nmax  47547, and than
 using Euler to reduce the interval (from 12 to nmax, then probably from (12
 + nmax)/2 to nmax, a.s.o)

 Then you will have ~ ln nmax computations of the function, which could be
 better than computing it from 1 to ...

I wish it was monotone, but it doesn't seem to be anything, I even plotted the
relation cathetus size x number of triangles, but it didn't really show any
pattern. It seems there are more likely results, but there are a few of them
that looks just random. If you want to see the plotted graph:

http://homepages.dcc.ufmg.br/~rafaelc/problem176.png
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Solving a geometry problem with Haskell

2008-01-12 Thread Rafael Almeida
Hello,

I have been browsing through the problems at projecteuler.net and I
found one that seemed interesting. It's the problem 176, I'll state it
here:

The four rectangular triangles with sides (9,12,15), (12,16,20),
(5,12,13) and (12,35,37) all have one of the shorter sides
(catheti) equal to 12. It can be shown that no other integer
sided rectangular triangle exists with one of the catheti equal
to 12.

Find the smallest integer that can be the length of a cathetus
of exactly 47547 different integer sided rectangular triangles.

I thought I've solved it nicely, only to find later on that my solution
was too slow (it has been running for almost three days now). While I
was creating my solution I used literate haskell, which I think helped
me a bunch to think about the problem. I wrote it originally in
portuguese -- the portuguese literate version has all the attempts I've
made until getting to the final one. For posting it here I've translated
the reasoning around the attempt that solved the problem -- although it
does it very slow -- into a new .lhs file:

http://www.dcc.ufmg.br/~rafaelc/problem176.lhs

After some profiling I found out that about 94% of the execution time is
spent in the ``isPerfectSquare'' function. So I began researching about
better ways to write that functio. Someone pointed to me on #haskell
that the C library gmp has such a function. So I went ahead and wrote a
C version of the program using gmp:

http://www.dcc.ufmg.br/~rafaelc/problem176.c

It's not the prettiest C code, as I did it really quickly, simply
translating haskell code into C, but I believe it works. That C solution
has been running for more than one hour now and no solution has come up
yet.  So I don't think it's worthed even writing a faster
isPerfectSquare in haskell.

As I was translating from Portuguese to English I revisited my logic and
I can't see any problems with it. I think the problem is only of
slowness, really. Does anyone have a better idea for how I should try to
solve this problem? I'm all out of ideas.

[]'s
Rafael
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] unification would give infinite type

2007-12-04 Thread Rafael
Hi... I give this error using hugs for the code:

---
f = foldl (\x y - add x y) 0 [1,2,3]
add x y = return (x + y)
---
I try:

f = foldl (\x y - counter x y) (return 0) [1,2,3]

but it dont solve,  and with ghci:


Occurs check: cannot construct the infinite type: b = m b
  Expected type: b
  Inferred type: m b
In the expression: add x y
In a lambda abstraction: \ x y - add x y


thnks.

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


Re: [Haskell-cafe] unification would give infinite type

2007-12-04 Thread Rafael
Hi Emil,  I'm beginning in monad area...

I don't know about monomorphis restriction, but foldM works, a lot of thanks...
Matias tnks too, i'm conscious about return in the monadic chain.

thnks.

On Dec 4, 2007 12:00 PM, Emil Axelsson [EMAIL PROTECTED] wrote:
 Hi,

 Depending on what you want, you should either remove 'return' or change to
 'foldM' (from Control.Monad). If you choose the latter, you also need to add a
 type signature to f (because of the monomorphism restriction).

 / Emil




 On 2007-12-04 14:43, Rafael wrote:
  Hi... I give this error using hugs for the code:
 
  ---
  f = foldl (\x y - add x y) 0 [1,2,3]
  add x y = return (x + y)
  ---
  I try:
 
  f = foldl (\x y - counter x y) (return 0) [1,2,3]
 
  but it dont solve,  and with ghci:
 
  
  Occurs check: cannot construct the infinite type: b = m b
Expected type: b
Inferred type: m b
  In the expression: add x y
  In a lambda abstraction: \ x y - add x y
  
 
  thnks.
 
  att
  Rafael
  ___
  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 mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] building a regular polygon

2007-08-19 Thread Rafael Almeida
On 8/19/07, Frank Buss [EMAIL PROTECTED] wrote:
  (*) Exercise 2.2
 
  Define a function regularPolygon :: Int - Side - Shape such that
  regularPolygon n s is a regular polygon with n sides, each of length
  s. (Hint: consider using some of Haskell's trigonometric
  functions, such
  as sin :: Float - Float, cos :: Float - Float, and tan :: Float -
  Float.)
snip
 import System

 type Shape = [Vertex]
 type Side = Float
 type Vertex = (Float, Float)

 regularPolygon :: Int - Side - Shape
 regularPolygon n s = (buildList n)
 where buildList 0 = []
   buildList i = let x  = cos(alpha) * s
 y  = sin(alpha) * s
 alpha = 2*pi/(fromIntegral n)*(fromIntegral i)
 in (x,y) : buildList (i-1)

That looks good, but I'd do like this:

regularPolygon :: Int - Side - Shape
regularPolygon n s = (buildList n)
   where buildList 0 = []
 buildList i = let x  = cos(alpha) * r
   y  = sin(alpha) * r
   alpha = 2*(fromIntegral i)*pi / fromIntegral n
   r = sqrt (s^2 / (2*(1 - cos (2*pi /
fromIntegral n
   in (x,y) : buildList (i-1)

I used the cosine law in order to calculate r. After all, s is
actually the size of the side of the polygon and not the distance of
its vertices from the origin.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


  1   2   >