[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dynamic vs. static typing

On 2003-11-24T11:44:32-0500, Joe Marshall wrote:
> If there is no `identity' for the objects in the list, then the list
> cannot be permuted (all `permutations' would be indistinguishable).

You can permute the list without -knowing- how to compare the objects
in the list for identity.  The caller of the permutation function may
well know more about the objects in the list than the list permutation
function needs to know.

    $ ghci
       ___         ___ _
      / _ \ /\  /\/ __(_)
     / /_\// /_/ / /  | |      GHC Interactive, version 6.0.1, for Haskell 98.
    / /_\\/ __  / /___| |      http://www.haskell.org/ghc/
    \____/\/ /_/\____/|_|      Type :? for help.
    Loading package base ... linking ... done.
    Prelude> let f x = "foo" ++ x
    Prelude> let g x = "bar" ++ x
    Prelude> let myList = [f, g]
    Prelude> let revlist = reverse myList
    Prelude> map (\h -> h "string") myList
    Prelude> map (\h -> h "string") revlist
    Prelude> :t reverse
    reverse :: forall a. [a] -> [a]
    Prelude> f == g
	No instance for (Eq ([Char] -> [Char]))
	  arising from use of `==' at <interactive>:1
	In the definition of `it': it = f == g

Note that even though Haskell gives me no way to compare the functions
f and g for identity, I was still able to invoke the permutation
function "reverse" on a list containing these functions.  I was able to
distinguish between myList and revlist, two lists of equal length, by
applying the functions in them to the string "string".

Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig
Sexy types in action: http://www.eecs.harvard.edu/~ccshan/cs252/usage.pdf
new journal Physical Biology: http://sansom.biop.ox.ac.uk/images/physbio.gif
What if All Chemists Went on Strike? (science fiction):

Attachment: signature.asc
Description: Digital signature