Ad
  • Custom User Avatar

    Okay, I'll have to bite: this kata is pointless in Haskell.

    First, it's because it's reimplementing Num and Fractional from scratch that also exactly matches them. Secondly, the design of using Data 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 the Num typeclass exactly so that:

    • you can add new Num instances by implementing the Num instance of your datatype, and then it automatically works
    • you can add new Num instances without modifying the Num definition itself (it's why making Num a datatype is a bad idea)
    • you don't have to write n^2 definitions for n types you have

    And 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.

  • Custom User Avatar

    Integer is definitely not an instance of Fractional. What's the supposed behaviour?

  • Custom User Avatar

    abs and signum of a complex number is not defined. As mentioned in the official docs, You need to have abs and signum respect the law

    abs n * signum n == n
    

    But this property is impossible for complex numbers.

    Also,

    data Number = Complex Number Number -- real imaginary

    Your definition of Number allows constructions like Complex (Complex (Real 0) (Real 1)) (Complex (Real 1) (Real 0)), which is absurd.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution