Records' syntax sucks ass. Let's look at this code example:
data VisualType = VisualType {
visualId :: Word32,
visualClass :: VisualClass,
bitsPerRgbValue :: Word8,
colormapEntries :: Word16,
redMask :: Word32,
greenMask :: Word32,
blueMask :: Word32
}
Here we:
Changing value of a field:
vtype {redMask = 666}
It's not a function. It's pure syntax shit. Cons are:
You can't curry this. To change field of every enrty in list, you'll have to make lambdas:
map (\vt -> vt {redMask = 666}) vtypes
To prevent namespace pollution, you can stick every data structure in module of its own and disambiguate like this:
VisualType.redMask vt
But that still sucks.
Possible solution of this would be adding something like C data structures, so you can do
vt ->redMask
Where "->redMask" is a postfix function, and it can be curried, passed aroud, or whetever. for changin fields, something like in ruby can be used:
vt ->redMask= 666
Where "->redMask=" is another postfix operator.
Also, you can get very nice runtime error if you write code like this
data Type = Cons1 { prop1 :: Int }
| Cons2 {prop2 :: Int }
main = print $ prop2 $ Cons1 {prop1 = 0}
Haskell has brilliant thing: infinite integral types.
Let us use them for indexes? Well, we can: there are genericLength and friends. If you use (:: [a] -> Int -> a) though, which is simplier, you are fucked if you suddenly need larger indexes. Indexes are barely a problem though.
Let us use Infinity like any other number? No. We can only get it, and NaN, as results of arithmetic operations, and check for them. Moreover, division by zero raises an error.
Other brilliant thing in Haskell: Maybe. But standard library seems to avoid it whenever necessary. Pass shit to read, !!
, tail, init, etc. and get an error.
There is no way to explicitly export instances. If you define an instance, it automatically gets exported whenever you want it or not. You can't explicitly import an instance either.
There are lot of problems with defining instances of complex types. For instance, if you define instance [a]
, you can't define separate instance of a [SomeType]