3 ms·
No real minuses discussed here so I thought I'd share some from my FP journey, which was SML -> OCaml -> Haskell -> Clojure. Each had its own sort of enlightenm
by millstone 8y ago
No real minuses discussed here so I thought I'd share some from my FP journey, which was SML -> OCaml -> Haskell -> Clojure. Each had its own sort of enlightenment, both in strengths and weaknesses.
IMO an under-appreciated weakness of Haskell is its culture of poor code quality and engineering practices, e.g. in how code is structured, (not) commented, or named.
Example, inspecting a graph in Haskell via fgl, we encounter the foundational Decomp type [1]:
type Decomp g a b = (MContext a b, g a b)
`a` and `b` are types, and in languages geared towards engineering, we would give them actual names: a is a NodeTag and b is an EdgeTag. But in Haskell it is customary to not provide this information, instead falling back on the type checker to ensure the code is consistent. There is not much effort put into useful naming: map vs mapM vs mapM_...
Second example, the simplex algorithm [2]:
addart :: (Num e, Enum a, Ix a, Num a) =>
Array (a, a) e -> Array (a, a) e
addart a = array ((-1,0),(n,m+n)) $ z ++ xsi ++ b ++ art ++ x
where z = ((-1,0), a!(0,0)) : [ ((-1,j),0) | j <- [1..n] ] ++ [ ((-1,j+n),a!(0,j)) | j <- [1..m] ]
xsi = ((0,0), -colsum a 0) : [ ((0,j),0) | j <- [1..n] ] ++ [ ((0,j+n), -colsum a j) | j <- [1..m] ]
b = [ ((i,0), a!(i,0)) | i <- [1..n] ]
art = [ ((i,j), if i == j then 1 else 0) | i <- [1..n], j <- [1..n] ]
x = [ ((i,j+n), a!(i,j)) | i <- [1..n], j <- [1..m] ]
((_,_),(n,m)) = bounds a
this code is astonishingly compact, but totally impenetrable. It has no comments, useful names, etc. This write-only code is typical
Haskell and its culture have significant weaknesses from an engineering perspective.
1: https://hackage.haskell.org/package/fgl-5.6.0.0/docs/Data-Graph-Inductive-Graph.html#t:Decomp https://hackage.haskell.org/package/fgl-5.6.0.0/docs/Data-Gr...
2: https://hackage.haskell.org/package/dsp-0.2.4/docs/src/Matrix-Simplex.html https://hackage.haskell.org/package/dsp-0.2.4/docs/src/Matri...
- ernst_klim 8y agoWhat I see is a typical mat crunching code, just like you would see in C++ or fortran, nothing haskell specific. Haskell examples you've attached are better commented than, say, eigen https://github.com/PX4/eigen/blob/master/Eigen/src/SparseCholesky/SimplicialCholesky_impl.h https://github.com/PX4/eigen/blob/master/Eigen/src/SparseCho... not to mention openblas https://github.com/xianyi/OpenBLAS/blob/develop/lapack/lauu2/zlauu2_U.c https://github.com/xianyi/OpenBLAS/blob/develop/lapack/lauu2...
- tutfbhuf 8y agoThis is not an representative code snippet. You can find such hard to read and entangled code in any programming language. I think a very good syntax comparison is offered by Rosetta Code, they show code solutions for over 800 programming task in many different languages https://rosettacode.org/wiki/Category:Programming_Tasks https://rosettacode.org/wiki/Category:Programming_Tasks
- garkin 8y agoWhy did you drop OCaml?
- cube2222 8y agoHow's your experience with clojure been so far?