[Haskell-cafe] What is your favourite Haskell "aha" moment?
Johannes Waldmann
johannes.waldmann at htwk-leipzig.de
Mon Jul 16 19:28:07 UTC 2018
> - Large-scale refactoring with types:
> this is a huge selling point for Haskell in general
I fully agree with the general idea, but the specific example
> data Shape
> = Circle Double
> | Square Double
> | Rectangle Double Double -- ^ added
is not convincing (well, to programmers
that know about static typing) Think of a Java program
interface Shape { .. }
class Circle implement Shape { ... }
When you add class Rectangle { } ,
then Shape foo = new Rectangle () would be an error,
until you put class Rectangle implements Shape { }
then the compiler tells you what methods are missing.
I think the extra value of types in Haskell
(for everything, including refactoring)
is that they tend to express more of the program's properties
(w.r.t. statically typed imperative programs).
Examples:
the distinction between a and IO a,
between IO a and STM a.
In Data.Set, function "fromList" has an Ord constraint,
but "toList" does not. Does "singleton" need the constraint?
I used this as an exam question just last week.
- J.W.
More information about the Haskell-Cafe
mailing list