[Haskell-cafe] Monad instance for partially applied type
constructor?
Christopher Done
chrisdone at googlemail.com
Wed Sep 29 14:12:27 EDT 2010
Maybe -XLiberalTypeSynonyms is an option:
http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/data-type-extensions.html#type-synonyms
On 29 September 2010 20:08, DavidA <polyomino at f2s.com> wrote:
> Hi,
>
> I have the following code:
>
> {-# LANGUAGE TypeSynonymInstances #-}
>
> data Vect k b = V [(k,b)]
> -- vector space over field k with basis b
> -- for example, V [(5, E 1), (7, E 2)] would represent the vector 5 e1 + 7 e2
>
> data Monomial v = M [(v,Int)]
> -- monomials over variables v
> -- for example, M [(A,3), (B,5)] would represent the monomial a^3 b^5
>
> type Poly k v = Vect k (Monomial v)
> -- multivariate polynomials over field k and variables v
>
> instance Monad (Poly k) where
> return v = V [(1, M [(v,1)])]
> p >>= f = ... -- variable substitution
>
> So my thinking is:
> 1. The Monad type class is for one parameter type constructors (eg [], IO)
> 2. Poly is a two-parameter type constructor
> 3. So Poly k is a one-parameter type constructor
> 4. What I'm trying to express, that polynomials over field k are a monad,
> is true.
>
> However, GHC 6.12.2 complains:
>
> Type synonym `Poly' should have 2 arguments, but has been given 1
> In the instance declaration for `Monad (Poly k)'
>
> What is going wrong?
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
More information about the Haskell-Cafe
mailing list