AM 9:00~12:00 PM 2:00~5:00 (中午休息,不接電話)
port 21

advance functional programming

dependent type ?

data Empty
data NonEmpty
data List x y where
Nil :: List a Empty
Cons:: a -> List a b -> List a NonEmpty

safeHead:: List x NonEmpty -> x
safeHead (Cons a b) = a

Yes, the classic approach: systematically derive programs from their
specification. The classic paper on that is

Paul Hudak. The Design of a Pretty-printing Library.

with a follow-up

Philip Wadler. A prettier printer.

The man who derives all his programs from specification is Richard
Bird. You may want to have a look at his recent sudoku solver

Richard Bird. A program to solve Sudoku.

where he starts with an apparently correct but hopelessly slow
specification and transforms it into a blazingly fast one. His
introduction to Haskell

Richard Bird.
Introduction to Functional Programming using Haskel (2nd edition).

emphasizes the classic style, too.

You may think "this is all nice, but my problem is too 'soft' for
mathematical laws and properties and such". Well, if you don't search,
you won't find. Here's an example for a "soft" problem domain:

Simon Peyton Jones, Jean-Marc Eber, Julian Seward.
Composing contracts: an adventure in financial engineering.

Of course, the laws "of nature" governing your problem domain may be
hard to find, so it may be worth to "just implement" and let some "law
intuition" guide you. Well-known example: darcs.

let v.s where

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License