gypsyface•

This is my own personal opinion but when I see highly optimized haskell code filed with unsafe this and unsafe unboxed array that I feel like a short c function would be a little more readable. Don't Get me wrong i love haskell but I don't think it's a perfect fit for everything

14
tailcalledOP•

I guess with both you and Killbot's points, it's probably fair to say that Haskell is not suitable for purely imperative programming.

3
joppux•

Introduction to Ben Lippmeier's thesis makes good points against this.

3
kamatsu•

That said, Ben Lippmeier himself still agrees that Haskell makes a better programming language (in general) than most, and prefers functional style programs to imperative ones.

1
[deleted]•
1
tailcalledOP•

Hmmm... I would probably implement it more like:

lastElt :: [a] -> Maybe a
lastElt xs = ($ (xs, Nothing)) . runState $
  do while (not . null <$> access list) $ do
       (x : xs) <- access list
       list ~= xs
       res ~= Just x
     first <$> get
 where
  list = _1
  res = _2

or using ST, not IO, but I see the problem...

5
whence•

How does that even work? What compiler settings are you using? Which modules do while, access, (~=), first, and get come from, and what are _1 and _2?

2
tailcalledOP•

while comes from the StackOverflow question Killbot posted. first is actually fst, from the prelude. ~= is actually .=, and access is actually use (Google is a traitor! Beware!) from lens. _1 and _2 access elements of tuples.

5
ky3•

In Haskell definitions are lightweight enough that it's a contender for A Very Fine Language for DSLs.

1
[deleted]•
  1. The whole point of imperative programming is to list step by step directions.

  2. The whole point of Haskell is to demand that programs fit in certain patterns, or fail to compile otherwise.

You can therefore make Haskell operate like #1. But why? Dr. Peyton-Jones argues that you can leverage the type system to rule out errors, even if programming in that quasi-imperative style. But I don't buy this. I find the cognitive load of programming in Haskell, of setting up everything so it can compile, too difficult.

-4
edwardkmett•

Fun fact: Like Robin Milner, Simon never actually bothered getting a PhD.

6
pipocaQuemada•

I find the cognitive load of programming in Haskell, of setting up everything so it can compile, too difficult.

Assuming that you're talking about getting a half-finished bit of code to compile, you're probably missing out on the wonders of undefined and holes.

undefined :: a

That is to say, undefined is valid value of any type, although it throws an error if you try to actually evaluate it. So we can take complex, half-written code, throw a couple undefines in it, and get it compiling. It's also useful when refactoring code, so you can test out refactored code as you go along.

Why is this useful? Because then you can focus on a single compiler error at a time, or load broken code into the repl to try to figure out how to fix it with some exploratory programming.

Holes are similar to undefined semantically, but ghc will print out a helpful message with the type of the hole and variables in scope when it comes across one (to help you figure out what to fill the hole with). For an example, see the Haskell Wiki:

5
kqr•

The "setting up everything so it can compile" part you are talking about simply means "writing a (somewhat) correct program." Besides the undefined and holes already mentioned, I don't really see why you would want to compile an incorrect program.

If you still want to do it though, there's -fdefer-type-errors which defers type errors to run-time, essentially granting you Python behaviour about that bit.

1
terrdc•

Haskell is built by academics and for academics. So among that field it is probably the best language all around.

So a more accurate claim would be that Haskell is the best academic language.

-7
jhickner•

I think thats true, but less true than it's ever been. The contribution of very practical libraries by people like bos have really opened the doors. I'm not an academic and Haskell is the main language I use at work (building automation and interactive installations).

3
liyang•

Some of us 'academic' types then go on to fairly reasonably paid jobs writing Haskell in industry. Problem?

3