[Haskell-cafe] Intro to functional dependencies in Haskell?
Marc Weber
marco-oweber at gmx.de
Thu Apr 17 04:05:47 EDT 2008
On Thu, Apr 17, 2008 at 03:21:16PM +1000, Alexis Hazell wrote:
> Hi all,
>
> i'm having some trouble 'getting' functional dependencies in the Haskell
> context (although my understanding of them in the context of relational
> database theory isn't that great either). Could someone please point me
> to an introduction / tutorial in this regard?
I think you've already tried www.haskell.org -> wiki search ?
http://haskell.org/haskellwiki/Functional_dependencies
You can express this by specifying a functional dependency, or fundep for short:
class Mult a b c | a b -> c where
(*) :: a -> b -> c
This tells Haskell that c is uniquely determined from a and b.
So there you can't implement instances
Mult Int Char Sting
and
Mult Int Char MyString
of course, your programs will work withou t that | a b -> c as well,
but you need to tell the compiler the result type of
(*) fac1 fac2
wheeras using fundeps it knows the result type becaus there can only be
one instance. (Which is what you want in this case when multiplying
matrizes as well.
HTH
Marc Weber
More information about the Haskell-Cafe
mailing list