Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Okay, I'll have to bite: this kata is pointless in Haskell.
First, it's because it's reimplementing
Num
andFractional
from scratch that also exactly matches them. Secondly, the design of usingData Number
with every type being a constructor is extremely dumb and very anti-Haskell, to the point that I'm suspecting you haven't read Learn You a Haskell at all: Haskell unifies every number datatype to theNum
typeclass exactly so that:Num
instances by implementing theNum
instance of your datatype, and then it automatically worksNum
instances without modifying theNum
definition itself (it's why makingNum
a datatype is a bad idea)n^2
definitions forn
types you haveAnd this is why you have all sorts of problems in the first place with
Complex
and such. It's because this entire kata is based on a very wrong approach.Integer
is definitely not an instance ofFractional
. What's the supposed behaviour?abs
andsignum
of a complex number is not defined. As mentioned in the official docs, You need to haveabs
andsignum
respect the lawBut this property is impossible for complex numbers.
Also,
Your definition of
Number
allows constructions likeComplex (Complex (Real 0) (Real 1)) (Complex (Real 1) (Real 0))
, which is absurd.This comment is hidden because it contains spoiler information about the solution