I'm not exactly sure what you're trying to do, but the problem is that you're trying to return a specific value where the type signature is polymorphic.<br><br>getParticleI returns a p, (with the constraint that p is a type in the class Particle) <br>
This means that getParticleI can be called in any context that needs a Particle p, but your getParticleI returns (Double, Double, Double) so it would only work in a context that needed a (Double, Double, Double), and the type signature doesn't reflect that, so you get an error.<br>
<br>To emphasize the problem, say I make a ParticleD<br>type ParticleD = (Int, Int)<br>
instance Particle ParticleD<br><br>let (a, b) = getParticleI myConfig 5 -- this is perfectly valid since ParticleD is a Particle, but doesn't work with your getParticleI definition because it returns a specific type (Double, Double, Double).<br>
Do you see what I mean?<br><br>You can fix it by either fixing the type of getParticleI:<br>getParticleI :: c -> Int -> ParticleC<br><br>or by using multiparameter type classes<br><br>class Configuration c p where<br>
getParticleI :: (Particle p) => c -> Int -> p<br><br>depending on what you're actually trying to do.<br><br>- Job<br><br><br><div class="gmail_quote">On Mon, Aug 17, 2009 at 2:35 AM, Grigory Sarnitskiy <span dir="ltr"><<a href="mailto:sargrigory@ya.ru">sargrigory@ya.ru</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello! I can't understand why the following dummy example doesn't work.<br>
<br>
{-# OPTIONS -XTypeSynonymInstances #-}<br>
{-# OPTIONS -XFlexibleInstances #-}<br>
module Main where<br>
import Data.Array.Unboxed<br>
<br>
class Particle p<br>
<br>
type ParticleC = (Double, Double, Double)<br>
instance Particle ParticleC<br>
<br>
class Configuration c where<br>
getParticleI :: (Particle p) => c -> Int -> p<br>
<br>
type Collection p = UArray (Int,Int) Double<br>
instance Configuration (Collection p) where<br>
getParticleI config i = (1,1,1) :: ParticleC<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
</blockquote></div><br>