On 19-Feb-1999, Michael Hobbs <[EMAIL PROTECTED]> wrote:
> [...] I wanted to respond in response to your last
> question about pattern matching on types. [...]
> 
> > typeName :: a -> String
> > typeName (x :: True) = "True"
> > typeName (x :: False) = "False"
> > typeName (x :: Int) = "Int"
> > typeName _ = "Unknown"
> 
> The problem with this concept, as I have it written out, is that it is
> dependent upon the ordering of the patterns.

Huh?  In Haskell, function definitions are in general
always dependent on the ordering of the patterns.

> For example, if in one
> module we define the following:
> 
> > write :: a -> b -> IO ()
> > write (ref :: IORef a) (x :: a) = writeIORef ref x
> > write (_ :: TTY) (x :: String) = print x
> > write _ (e :: Error) = exitWith (errorVal e)
> 
> And in a different module, we define:
> 
> > write (_ :: MVar String) x = putMVar mvar (show x)
>
> What would happen if `write' was called with an MVar variable and an
> Error variable? Would the `exitWith' function get called, or would the
> `putMVar' function get called?

Haskell doesn't normally let you define clauses for the same function
in different modules.  So this case should just be disallowed.

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "Binaries may die
WWW: <http://www.cs.mu.oz.au/~fjh>  |   but source code lives forever"
PGP: finger [EMAIL PROTECTED]        |     -- leaked Microsoft memo.



Reply via email to