Pages

20190211

The Little MLer by Matthias Felleisen & Daniel P. Friedman


  • Most large computer programs are never completely understood; if they were, they wouldn’t go wrong so often and we would be able to describe what they do in a scientific way. A good language should help to improve this state of affairs.
  • Programs consume data and produce data; designing a program requires a thorough understanding of data. In ML, programmers can express their understanding of the data using the sublanguage of types. Once the types are formulated, the design of the program follows naturally.
  • Most collections of data, and hence most type specifications, are inductive, that is, they are defined in terms of themselves. Hence, most programs are recursive; again, they are defined in terms of themselves.
  • A type is a name for a collection of values.
  • The First Moral
    • Use datatype to describe types. When a type contains lots of values, the data type definition refers to itself. Use alpha with datatype to define shapes.
  • The Second Moral
    • The number and order of the patterns in the definition of a function should match that of the definition of the consumed data type.
  • The Third Moral
    • Functions that produce values of a data type must use the associated constructors to build data of that type.
  • The Fourth Moral
    • Some functions consume values of star type; some produce values of star type.
  • The Fifth Moral
    • Write the first draft of a function following all the morals. When it is correct and no sooner, simplify.
  • The Sixth Moral
    • As datatype definitions get more complicated, so do the functions over them.
  • The Seventh Moral
    • Some functions consume values of arrow type; some produce values of arrow type.
  • The Eighth Moral
    • Replace stars by arrows to reduce the number of values consumed and to increase the generality of the function defined.
  • The Ninth Moral
    • Some functions produce exceptions instead of value; some don’t produce anything. Handle raised exceptions carefully.
  • The Tenth Moral
    • Real programs consist of many components. Specify the dependencies among these components using signatures and functors.

No comments:

Post a Comment