data Ray = Ray Vector Vector
or
type Ray = (Vector, Vector)
Which is preferred in idiomatic haskell? Why should I use one over the other?
I don’t care about performance.
It seems to make little difference with functions, e.g.:
trace :: Ray -> …
trace (Ray x d) = …
-- OR
trace (x, d) = …
The
dataversion is preferred as it more clearly indicates the intent of the programmer — by creating a new type, you are pointing out to all that this is not merely a tuple, but a meaningful semantic entity, aRay.That then makes it possible to lean on the type system further, with custom instances for
Ray, and optimizations not possible in tuples.