Re: [Haskell-cafe] pointer equality

2011-07-21 Thread Pedro Vasconcelos
On Wed, 20 Jul 2011 12:48:48 -0300
Thiago Negri evoh...@gmail.com wrote:


 Is it possible to implement (==) that first check these thunks before
 evaluating it? (Considering both arguments has pure types).
 
 
 E.g.,
 
 Equivalent thunks, evaluates to True, does not need to evaluate its
 arguments: [1..] == [1..]
 
 

Thunks are just expressions and equality of expressions is undecidable
in any Turing-complete language (like any general-purpose programming
language). Note that syntactical equality is not sufficient because
(==) should be referentially transparent.

Pedro

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


Re: [Haskell-cafe] Input and output of mathematical expressions

2011-06-13 Thread Pedro Vasconcelos
On Thu, 9 Jun 2011 16:23:20 +0200
Jacek Generowicz jacek.generow...@cern.ch wrote:

 Greetings Cafe,
 
 What would you recommend as a Haskell-based means of interactively  
 reading and writing mathematical formulae?
 
 As a toy example, what might I use to write a program which presents  
 the user with
 
  Please simplify the expression: \pi x^2 + 3\pi x^2
 
 (Where the TeX-style expression would be presented with a greek pi
 and superscript twos on the xs.)
 
 The user should then have the ability to reply with something that  
 looks like the result of TeXing
 
  5 \pi x^2
 
 Whatever means the user uses to enter this expression, he should be  
 able to preview the typeset version of his input before submitting.
 
 Any ideas?
 
 Thanks.
 


Regarding the rendering math formulas on web browsers: you might want to
have a look at MathJax (http://www.mathjax.org/). You can use LaTeX or
MathML and will work in most browsers (even if when they don't natively
support MathML).

Pedro

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


[Haskell-cafe] Distributing Haskell GUI apps for Windows/MacOS?

2011-06-07 Thread Pedro Vasconcelos

Hello,

I've implemented a Haskell program to play a modern board game. I've
put it on Hackage (http://hackage.haskell.org/package/hstzaar)
but would also like to distribute to people without the Haskell
development tools. 
Are there any easy ways of making installers for Windows/MacOS
(preferably using free or open source tools)?

Best regards,

Pedro

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


Re: [Haskell-cafe] Haskell on-line judge for Programming Challenges / Contests ?

2011-04-14 Thread Pedro Vasconcelos
On Thu, 14 Apr 2011 13:29:48 +0400
Dmitri O.Kondratiev doko...@gmail.com wrote:

 Hello,
 I am looking for a site providing on-line automatic judge for
 Programming Challenges that can be coded in Haskell.
 For example this site:
 http://www.programming-challenges.com
 provides lots of interesting programming provlems:
 http://www.programming-challenges.com/pg.php?page=index
 
 Yet, unfortunately only C, C++ and Java code can be submitted,  judge
 on that site can't compile and run Haskell code.
 Is there any similar online judge for Haskell?
 
 Thanks,
 Dmitri

Althpugh not Haskell-specific, the Mooshak system for managing
programming contests on the Web allows you to configure most programming
languages:

http://mooshak.dcc.fc.up.pt/

It's been developed our CS department and used internally and
externally for programming contests and courses.

Pedro

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


Re: [Haskell-cafe] Proving correctness

2011-02-14 Thread Pedro Vasconcelos
On Sat, 12 Feb 2011 19:38:31 +0530
C K Kashyap ckkash...@gmail.com wrote:

 Anyway, how can one go about explaining to an imperative programmer
 with no FP exposure - what aspect of Haskell makes it easy to
 refactor?


Like other people have said, the static type system is a major factor.
It's true that Haskell's type system is more advanced than most
imperative languages but it's also the often not mentioned that static
typing gives a stronger check in a functional language than an
imperative ones even in simple cases. This is because all input and
output data flow is type checked in a function application, whereas
imperative side effects might escape checking. 

For example, the type signature for a variable swapping procedure in C:

void swap(int *a, int *b)

This will still type check even if it modified only one of the argument
references. However, if written functionally, it must return a pair:

swap :: (Int,Int) - (Int,Int)

Now the type checker will reject any implementation that fails to
return a pair of results in every case. Of course for a trivial example
like swap this is easy to ensure in any imperative language, but for
more complex programs it is actually quite common to forget some update
some component of the state.

BTW, I found this and other interesting reflections on the avantages of
FP vs. imperative in Martin Oderski's book Programming in Scala.

Best regards,

Pedro Vasconcelos



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


Re: [Haskell-cafe] Proving correctness

2011-02-14 Thread Pedro Vasconcelos
On Mon, 14 Feb 2011 12:54:55 +0100
Tillmann Rendel ren...@informatik.uni-marburg.de wrote:

 This benefit of explicit input and output values can interact nicely 
 with parametric polymorphism:
 
swap :: (a, b) - (b, a)
 
 This more general type signature makes sure we are not just returning 
 the input values unswapped.
 

Good point. This is a good reason why it's good practice to look for
possiblity of writing more general functions and types even when
they end up being used in a single instance.

Pedro

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


Re: [Haskell-cafe] Proving correctness

2011-02-14 Thread Pedro Vasconcelos
On Mon, 14 Feb 2011 15:07:01 +0100
Gábor Lehel illiss...@gmail.com wrote:

 I'm not completely sure, but I suspect another part of it (or maybe
 I'm just rephrasing what you said?) has to do with the fact that in
 Haskell, basically everything is an expression. 
 

Yes, the fact that control statements (e.g. if-then-else) are
expressions makes type checking much more effective. However, I think
this is somewhat lost when programming imperative code in Haskell using
a state or I/O monad (because a monadic type such as IO t does not
discriminate what effects might take place, only the result type t).
Of course one can use a more specialized monad (such ST for
mutable references, etc.). I don't think that my imperative
programs are automatically made more correct by writing them as
monadic code in Haskell --- only that in Haskell I can opt for the
functional style most of the time.

BTW (slightly off topic) I found particularly annoying when
teaching Python to be forced to use an imperative style
(e.g. if-then-else are always statements). Scala is must better in this
regard (altought it is not purely functional language); a statement is
simply an expression whose return is unit.


Pedro

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


Re: [Haskell-cafe] Haskell, C and Matrix Multiplication

2011-01-17 Thread Pedro Vasconcelos
On Mon, 17 Jan 2011 07:45:04 +
Blake Rain blake.r...@gmail.com wrote:

 So, after drinking  some coffee and having a  smoke, I started the
 Haskell version:
 
 [foldl (+) 0 $ zipWith (*) x y | x - m1, y - transpose m2]
 

I don't think this is correct; it's type is 

(Num a) = [[a]] - [[a]] - [a]

rather than the expected

(Num a) = [[a]] - [[a]] - [[a]]

How about:

mult m1 m2 = [[foldl (+) 0 $ zipWith (*) x y |  y-transpose m2] | x-m1]

Regarding performance: did you make sure you're forcing the
evaluation of the result matrix? 

Regards,

Pedro

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


Re: [Haskell-cafe] Haskell, C and Matrix Multiplication

2011-01-17 Thread Pedro Vasconcelos
On Mon, 17 Jan 2011 10:38:30 +
Blake Rain blake.r...@gmail.com wrote:

 So sorry, I meant:
 
 mult :: (Num a) = [[a]] - [[a]] - [a]
 mult m1 m2 = [foldl (+) 0 $ zipWith (*) x y | x - m1, y - transpose
 m2]
 

Shouldn't the result of multiplying an (n,k)-matrix by an (k,m)-matrix
be an (n,m)-matrix? The way you've written it the result will be a list
of length n*m.

 
  
  Regarding performance: did you make sure you're forcing the
  evaluation of the result matrix? 
 
 I thought I was. It's printing the results as expected. Could be I'm
 just imagining I am and suffering a delusion or misunderstanding.
 

Another issue to look out for is let-floating: if you perform the same
matrix multiplication repeatedly, the compiler might very well lift
the matrix calculation outside the loop.

Pedro

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


Re: [Haskell-cafe] Not in scope: type constructor or class `Map'

2010-12-30 Thread Pedro Vasconcelos
On Thu, 30 Dec 2010 08:01:01 -0800 (PST)
michael rice nowg...@yahoo.com wrote:

 Not sure what's going on here. Doesn't like line 5, the type
 statement. And what's with the semicolons in that line and in
 function main?

 
 import Control.Monad.Reader
 import qualified Data.Map as Map
 import Data.Maybe
 
 type Bindings = Map String Int;
.
The right hand side should be Map.Map String Int; alternatively
add an unqualified import above for just the Map type:

 import Data.Map(Map)

The semicolon is optional---the layout rule will insert it if you leave
it out.


Pedro

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