Re: [Haskell-cafe] Int vs Integer?

2005-05-05 Thread Cale Gibbard
Int is the type of machine integers, with guaranteed range at least
-2^29 to 2^29 - 1, while Integer is arbitrary precision integers, with
range as large as you have memory for.

The code you gave, on its own, is fine. The types inferred by ghci are
ints :: [Int]
and
prng :: [[Int]]

Hugs seems to choke on it though. If you provide an explicit type
signature for ints, it works fine. It seems to be defaulting the type
to [Integer] a little too early. I expect you'll replace ints with a
more interesting list, as ints !! i is currently equal to i.

If you need to coerce something of integral (Int, Integer) type to any
numeric type, use fromIntegral.

hope this helps,
 - Cale
On 5/5/05, Daniel Carrera [EMAIL PROTECTED] wrote:
 Hello,
 
 What's the difference between Int and Integer?
 
 How can I tell Haskell which one I want? I'm having trouble with a function:
 
 ints = 0 : map (1+) ints
 prng = map iter ints
   where iter 0 = [0,0]
 iter n = [i,j]
  where i = mod n 256
j = ints !! i
 
 (eventually 'iter' will be more a more interesting function).
 
 When I try to load this module in Hugs I get the error:
 
 ERROR ./PRNG.hs:24 - Type error in list
 *** Expression : [i,j]
 *** Term   : j
 *** Type   : Integer
 *** Does not match : Int
 
 Line 24 is the 'prng' line. I've spent all day trying to fix this, but
 for the life of me I can't figure out why it happens or how to make it
 stop. Haskell just doesn't seem to like the 'iter !! i' construct.
 
 It's interesting that if you replace 'i' by (say) 3, Haskell runs the
 program happily. But, if you replace 'i = mod n 256' by 'i=3' you get
 the same error.
 
 Any words of wisdom would be appreciated.
 
 Cheers,
 Daniel.
 ___
 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] How to show a variable with show?

2005-05-05 Thread Michael Onofruk
Hi!
In my program I would like to see an result of
function or an variable.
Wenn I use show myfunction or show variable, I'm
getting errors like ERROR - Improperly terminated
character constant or  Syntax error in declaration
(unexpected `;', possibly due to bad layout)

Any help would be appreciated!




Yahoo! Mail
Stay connected, organized, and protected. Take the tour:
http://tour.mail.yahoo.com/mailtour.html

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


Re: [Haskell-cafe] Re: Haskell vs OCaml

2005-05-05 Thread Duncan Coutts
On Wed, 2005-05-04 at 18:29 -0400, Jacques Carette wrote:
 There is also Template Haskell vs MetaOCaml.
 
 For the life of me, I still cannot fathom why Template Haskell is untyped, 
 while MetaOCaml is fully typed.  Which is 
 the main reason I write meta-program in MetaOCaml and 'other' programs in 
 Haskell.

The reason for this is that Template Haskell is more powerful and
correspondingly harder to type so it is currently untyped.

The main reason it is more porwerful is that TH allows you to pattern
match on the abstract syntax of a quoted expression and perform
arbitrary transformations on that. It would be hard to preserve the
well-typedness of the AST and still allow arbitrary transformations.

A colleague of mine is currently developing a type system for Template
Haskell that should catch most errors without restricting too much the
programs you can write.

Duncan

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


Re: [Haskell-cafe] NumberTheory library

2005-05-05 Thread Bo Herlin
You might want to check out the archives of the mailing list, too.  These
sorts of problems occasionally get solved.  For the record, here are a few
of my attempts:
http://andrew.bromage.org/Fib.hs (Fairly fast Fibonacci numbers)
http://andrew.bromage.org/WheelPrime.hs  (Fast factorisation)
http://andrew.bromage.org/Prime.hs   (AKS primality testing)
Great, why not put these together in a first attempt of making a 
standard library? Or is the road to creating standard libraries starting 
somewhere else? I actually dont know.

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


Re: [Haskell-cafe] How to show a variable with show?

2005-05-05 Thread Mads Lindstrøm
Hi

  module Main where
  
  main = do putStr (show (foo 3))
putStr \n
putStr (show (foo 7))
putStr \n
putStr (show y)
  
  foo x = (x + 2) / y where
  y = 2 * 2
  
 And how do I see functions or variables defined
 inside of other functions? In example above - y
 

Short answer -- you don't. 

Haskell is a purely functional langauge and functions can therefore not
have side effects. Side effects can only occur in the IO monad (and
maybe in some other monads) as shown above in main, which really is a IO
monad with type main :: IO(). Therefore you cannot print the value of
y to the screen in the middle of the foo function.

This may seem like a stupid limitation, but restricting your functions
to be pure eliminates a lot of errors. And in my, albeit limited Haskell
experience, there is rarely a need to see the value of variables writen
inside other funcitons (as shown in your example).

If you really need this kind of feedback, then there are some debugging
tools here: http://www.haskell.org/libraries/#tracing which may do it
for you. However, I have tried none of them and do not really know what
they can do.

hope it helps,

Mads Lindstrøm [EMAIL PROTECTED]

 
   
 Yahoo! Mail
 Stay connected, organized, and protected. Take the tour:
 http://tour.mail.yahoo.com/mailtour.html
 
 ___
 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] How to show a variable with show?

2005-05-05 Thread Michael Onofruk

   
  And how do I see functions or variables defined
  inside of other functions? In example above - y
  
 
 Short answer -- you don't. 
 

Thanks for explanations!
Cheers, M.



__ 
Do you Yahoo!? 
Yahoo! Mail - Helps protect you from nasty viruses. 
http://promotions.yahoo.com/new_mail
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Haskell vs OCaml

2005-05-05 Thread Jacques Carette




Duncan Coutts wrote:

  On Wed, 2005-05-04 at 18:29 -0400, Jacques Carette wrote:
  
  
There is also Template Haskell vs MetaOCaml.

For the life of me, I still cannot fathom why Template Haskell is untyped, while MetaOCaml is fully typed.  Which is 
the main reason I write meta-program in MetaOCaml and 'other' programs in Haskell.

  
  
The reason for this is that Template Haskell is more powerful and
correspondingly harder to type so it is currently untyped.
  

``more powerful'' meaning that it can do some level of introspection,
right? I know introspection can be very powerful (I designed Maple's
modern reflection and reification facilities...), but I was under the
impression that type systems that can handle 'too much' introspection
were unsound [a result of Walid Taha].

  The main reason it is more porwerful is that TH allows you to pattern
match on the abstract syntax of a quoted _expression_ and perform
arbitrary transformations on that. It would be hard to preserve the
well-typedness of the AST and still allow arbitrary transformations.
  

Can't this be regarded as a 'convenience' rather than as actual extra
power? Using an abstract interpretation formalism (see papers of Taha
and co-authors), it is possible to 'lift' the type of code values into
staging-time terms, and pattern-match on that instead. Then
well-typedness of transformations is much easier to show. In this way
one can even implement some transformations that are equivalent to what
are currently 'hints' to GHC as well-typed code [I have some code that
does this, but there are only hints of this in a preprint of mine --
see the conclusion section of "Gaussian
Elimination: a case study in efficient genericity with MetaOCaml" available
from http://www.cas.mcmaster.ca/~carette/publications.html for some
hints on how this is done

  A colleague of mine is currently developing a type system for Template
Haskell that should catch most errors without restricting too much the
programs you can write.
  

I am eagerly awaiting this! Writing Monadic meta-programs in MetaOCaml
is feasible, but the lack of native support for Monads makes it
significantly harder. But after spending 12 years writing programs in
a fully dynamically typed language (Maple), I am much happier writing all
parts of my programs in a strongly typed language!

Jacques


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


RE: [Haskell-cafe] Conal Elliott's Vertigo, anyone get it to run?

2005-05-05 Thread Atwood, John Wesley
 On 5/5/05, Atwood, John Wesley [EMAIL PROTECTED] wrote:
  I tried to run Conal Elliott's Vertigo demos, on 3 diffferent XP 
  boxes; it ran on none.  The error is Common Language Runtime
Services  
  - Appication has generated an exception that could not be handled.
  Process id=, Thread id=.  Any suggestions?
  http://conal.net/Vertigo/
  
 On 5/5/05, Sebastian Sylvan [mailto:[EMAIL PROTECTED] wrote:
 Do you have .Net installed?
 
 I got it to run, don't know what  you're doing wrong.
 

Yep, version 1.1; don't have the C# compiler installed, but it's my
understanding that that's not needed for the demos.


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


Re: [Haskell-cafe] Squashing space leaks

2005-05-05 Thread Greg Buchholz
Josef Svenningsson wrote:
 I think the thing that really kills you is the way you shuffle around
 the list in the advance function. Your commented out rotations
 function has the same problem. Here is my attempt to solve the problem
 a little more efficiently:

We're heading in the right direction anyway.  I can now compute 1
million iteration in about 2 minutes (with +RTS -H750M -K100M).  Well
almost, since it now doesn't compute the right answer, so something must
be amiss in the shuffling section.  Now if we can get it to us a little
less than 1G of memory, we'll be in good shape.

Thanks,

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