Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Haskell compiler or preprocessor that uses strict evaluation?

Tags:

I'm looking for a Haskell compiler that uses strict evaluation by default instead of lazy evaluation. I would just use OCaml, but Haskell's syntax is so much better than OCaml's (and Haskell is pure, and has cool features such as type classes).

I'd really rather not constantly put !s and $!s all over my program. A compiler with a switch or a preprocessor to put in the strictness annotations would be really nice. It would also be helpful if there was a way to use lazy evaluation in certain places too, just in case I want something like an infinite list (I probably never will).

Please do not try to convince me that lazy evaluation is better, I really need the performance. IIRC, Simon Peyton Jones even said that lazy evaluation wasn't really necessary, it was there mostly to prevent them from making the language impure.

like image 319
Zifre Avatar asked Jun 15 '09 13:06

Zifre


People also ask

What is strict evaluation in Haskell?

A new Strict language extension to Haskell aims to make it easier to use Haskell for code that is meant to be mostly strict, i.e., evaluated in a non-lazy manner. The feature was recently merged into GHC's git HEAD and will be included in GHC's next release.

What is a strict function in Haskell?

No, it's not a function whose arguments are evaluated before the call. A strict function is, informally, a function which evaluates its arguments.

Does Haskell use lazy evaluation by default?

Haskell uses lazy evaluation by default, which makes it hard to reason about the space usage (or termination) of a particular program. OCaml on the other hand is not lazy by default (but supports it if you need it).

Does Haskell have a compiler?

The compiler (written in Haskell), translates Haskell to C, assembly, LLVM bitcode and other formats. The strategy it uses is described best here: Implementing lazy functional languages on stock hardware:the Spineless Tagless G-machine.


2 Answers

I'd really rather not constantly put !s and $!s all over my program

You're doing it wrong, if that's how you're programming Haskell :) You simply won't need to do this. Use GHC, use -O2, use strict data types when appropriate, use lazy ones when appropriate. Don't assume laziness is going to be a problem - it is a solution to a lot of problems.

like image 102
Don Stewart Avatar answered Oct 18 '22 12:10

Don Stewart


If you have a Haskell compiler that uses strict evaluation, it doesn't compile Haskell. Laziness Non-strictness is part of the Haskell spec!

However, there are alternatives.

  • DDC is an attempt to create an explicitly lazy variant of Haskell which supports things like destructive update whilst retaining all the rest of Haskell's goodness. There is one problem: the compiler is currently only in the α-stage, although it seems to be at least usable.

  • Create a preprocessor, as others have done.

  • Learn to use Haskell “the right way”. If you can simplify your test case down to something which is publicly-displayable, you could post it on the Haskell-Café mailing list, where people are very helpful with these sorts of questions concerning the effects of non-strictness.

like image 43
porges Avatar answered Oct 18 '22 14:10

porges