I posted this comment at http://blog.matthewdoig.com/?p=152
Thanks Matthew et al.
RE:
" ... I have to admit that just finding a good example was somewhat of a chore, which suggests either functors aren’t used a whole lot by OCaml programmers or nobody understands them. ... " Matthew Doig
" ... but compositionality is the core feature of functional programming. Ocaml style functors and Haskell style monads just aren’t possible in F#. Sure, we can simulate composibility, but the above example shows that it’s still too difficult. ..." Anonymous
" ... I’m just saying: it’s natural to be frustrated when translating a concept in one language to another that doesn’t have direct support for it. ... " Kurt
Is a good example of functors in OCAML, "Tilings as a programming exercise" by Guy Cousineau, (Theoretical Computer Science 281 (2002) 207 – 217) [also with Mauny "The Functional Approach to Programming"]?
Trying to translate it to F# led to "The Haskell School of Expression, Learning Functional Programming Through Multimedia", by Paul Hudak.
Here's the conclusion:
" Now we can summarize the construction of tilings in one functor that takes all the necessary ingredients as parameters:
module Construct_tiling
(Group: CANONICAL_GROUP)
(Geom: GEOMETRY)
(GenMap: MAPPING with type source = Group.element
and type dest = Geom.transformation)
(GenColorMap: MAPPING with type source = Group.element
and type dest = Permutation.permutation)
(Tile: TILE with type transformation =
Geom.transformation * Permutation.permutation)
=
Make_tiling
(Make_generator_from_canonical
(Make_canonical_generator(Group))
(MakePair (Make_morphism (Group) (GenMap) (Geom.Tgroup))
(Make_color_morphism (Group) (GenColormap)))
(Tile)
This leads to a simplified graphical representation which appears in Fig. 3.
7. Conclusion
What we have obtained is a very generic program that can produce any tiling with a computable symmetry group that operate transitively on the tiles. ..."
No comments:
Post a Comment