
On Tue, Jun 26, 2012 at 06:39:11PM -0400, Jay Sulzberger wrote:
On Tue, 26 Jun 2012, Alec Story
wrote: Because of Haskell's type system, there are some expressions that you simply cannot compile. Most of them you don't *want* to compile because they do bad things (like add two strings, for example). Some things are legal in Lisp but don't typecheck in Haskell for exactly the reasons that Brent pointed out. They might make sense in some contexts, but the compiler isn't able to reason about them.
Thanks, Alec.
What is a formalized version of
It is not possible in Haskell to define `applyTo`.* * At least not without crazy type class hackery.
I think the difficulty must arise mainly from the *, meaning I think, "any type" in the above `applyTo`.*. Would it be easy/convenient to define `applyTo`.(a, b, c) where a is a "type variable"? In general can we, for any finite number n, where n > 2, easily/conveniently define `applyTo`.(a1, a2, ..., an) ?
Haha, sorry, it seems my meta-notation was confusing. `applyTo`.* is `applyTo`, followed by a period (indicating the end of the sentence), followed by an asterisk (indicating the presence of a footnote). It is not a technical notation at all. =) In any case, yes, you can define `applyTo` for any specific number of parameters. For example, applyTo3 :: (a -> a -> a -> b) -> [a] -> b applyTo3 f [x,y,z] = f x y z (although I do not recommend even this, because applyTo3 will crash if you pass it a list of the wrong length). But you cannot define a single `applyTo` which works for any number of parameters. The problem is that every expression in Haskell must have a type, and Haskell's type system is not expressive enough to write down a valid type for applyTo. (What would the type of its first argument be?) -Brent