[Haskell-cafe] what do you think of haskell ? (yes,
it's a bit general ...:)
brianh at metamilk.com
Thu Jun 15 18:18:24 EDT 2006
minh thu wrote:
> hi all folks,
> i'm diving into haskell for more than one year now.
> the reason for that is just that i like haskell.
> (i'm a computer science student)
> but i consider to move back to c/c++.
There is also OCaml and SML, both of which have freely available compilers
to generate fast native code (SML has MLton - a whole program optimizing
compiler), and which use side effects instead of monads.
> here are my thoughts.
> i've no specific question but i'd like to have your opinion.
> here we go:
> haskell is really nice : short phrased, declarative, math-feeling, the
> type system ensure low bug amount (i surely forget other nice things).
> but haskell is quite ugly in some way :
> * array : if i want to write something involving array, i could use
Bulat's written a new array library - see
> but with iouarray, i cant use an array of MyType; i have to use an
> array of (say) float (it's ok if i have only float in MyType).
> that kind of thing is what i think is *really* low-level.
> in c, i can have an array of what-i-want.
There is a compromise between using IOArray versus IOUArray. IOArrays might
even be more efficient than unboxed arrays in some situations:
1) When (large) elements are shared between different arrays or different
data structures, since only the pointer needs to be copied
2) Compared to C++ templates, only one piece of code needs to be generated
to handle them, so there might be fewer cache misses at runtime
> * randomIO
> side-effect is nicely resolved with monad. and you have to thread
> your state. if you're writing your monad or use a transformer, things
> are quite explicitly (even if it's implicit in the do notation)
> but the threading of the randomIO argument is really not explicit for
> me : it just means that the underlying/threaded state in the IO monad
> can encapsulated a lot of things.
> it feels exactly like a c function. but usually, you cant design a
> c-like function in haskell (i.e. a function with state).
You can instead write a function that returns an action in whatever monad
you're using. For example using a Reader monad to hold IORefs, you can
easily update the state of these IORefs. Of course this is more work than
just declaring some global variable in C and updating it in the function,
but it gives you more flexibility in the long run - you now have full
control over the environment that the function sees, just by running it in
another Reader containing different IORefs.
> * more things i dont remember...
> * generally
> my general feeling for haskell vs c is:
> in haskell i always have to learn new things to get my work done ;
> although haskell is really easy to learn in the first step, it's
> becoming increasingly hard to get what's the *trick* to do what i
Maybe you are expecting too much of your code. A while back I was agonizing
over the perfect way to write something using higher order functions, then a
comment by Bulat (
http://www.haskell.org//pipermail/haskell-cafe/2006-May/015540.html ) helped
me put things in perspective:
imho, it's typical functional style,
but without using higher-level functions
So now I just concentrate on getting code to work and leave the highly
obfuscated cleverness for later... ;-)
> e.g. writing myfunction x1 .. xn | x1 `seq` ... False = undefined is
> not declarative
> (and i still have to learn to identify where it helps and where it
Bang patterns would at least make the syntax easier to write. Strictness
annotations work both ways - perhaps the question should be: where does
*lazyness* help? I don't think anyone really has a clear answer to this at
> the c language take some more time to learn at the beginning but
> that's it! what you can learn by after is better c programming.
I think (as someone who has spent at least 16 years programming in C++) that
there are millions of complicated things there as well. The syntax and
semantics of a language is only the very start. C and C++ have idioms to
learn too, and like anything, it takes a lot of time and experience to know
which "trick" to use in a given situation. Just as the object oriented
community has spent many years slowly trying to understand how to design
object oriented programs and made major mistakes at the beginning (eg using
implementation inheritance instead of interfaces and composition (exactly
what is fully supported in Haskell by classes and instances)).
> there are memory management, pointers, side-effects, but you can do
> what you want, it behaves as expected and you dont have to learn (in a
> academic paper) how to use an array or how to do io.
Haskell has a difficult learning curve. I remember the first few times I
looked at the type signatures for the methods of Data.IArray and it was
certainly not at all clear! :-) In the worst case, you can always use the
FFI to link with some C if there is some especially tricky low level
operation that needs to be very fast.
> please don't tell me "you're stupid, go back to your c and leave this
> glorious mailing list"
> did you had the same feeling ? does it disappear ? how ?
I think it just takes time to gradually understand enough to write whatever
program you're writing. There are lots of useful tutorials on the wiki (both
old and new wiki). To understand things like monads and monad transformers,
you can also look at the Haskell source (available from ghc wiki for
example) to see that they are not so complicated as they appear if you only
look at the Haddock documentation which only gives the type signatures.
Logic empowers us and Love gives us purpose.
Yet still phantoms restless for eras long past,
congealed in the present in unthought forms,
strive mightily unseen to destroy us.
More information about the Haskell-Cafe