[Haskell-cafe] Functional dependence nightmare

Edgar Gomes Araujo talktoedgar at gmail.com
Sun Mar 27 01:59:28 CET 2011


Dear Stephan,

Finally!!!! It's alive and working, huhhuu! After 3 long days...

As predictable, it was my fault. There was basically two big mistakes:

-  splitAF::(SubUnit a b, Ord a)=>BoxPair -> ActiveSubUnit a -> StateMBC a
()
instead of "splitAF::(SubUnit a, Ord a)=> BoxPair -> a -> StateMBC a ()"

-  type SetActiveSubUnits a = Set (ActiveSubUnit a)
instead of "type SetActiveSubUnits a = Set a"

After those corrections there was one error remaining:

src/DeUni.hs:264:39:
    Could not deduce (Unit a ~ Unit subUnit0)
    from the context (SubUnit a, Ord a)
      bound by the type signature for
                 mbc :: (SubUnit a, Ord a) =>  [Point] -> SetActiveSubUnits
a -> Box -> StateMBC a [Unit a]
      at src/DeUni.hs:(253,1)-(310,53)
    NB: `Unit' is a type function, and may not be injective
    Expected type: [Unit a]
      Actual type: [Unit subUnit0]

Then I decided to go back to Fun Dep instead of GADT due the "injective"
complain.

class SubUnit subUnit unit | subUnit -> unit, unit -> subUnit where
    .....

instead of

class SubUnit subUnit where
    type Unit subUnit :: *
    .....

And ... Bingo!

My last question, how can I make it work using GADT?

Thank so much for your kindly assistance.

Edgar



On 26 March 2011 23:13, Stephen Tetley <stephen.tetley at gmail.com> wrote:

> Hi Edgar
>
> I think you have some errors of construction rather than just a
> problem with the type families / fun deps.
>
> Note, I've knocked off the class constraints on the data declarations
> on the copy I'm working with (e.g ActiveSubUnit) , this may or may not
> change things.
>
> This change to splitAF will type check, whether or not it does what you
> want:
>
> > splitAF::(SubUnit a, Ord a)=> BoxPair -> a -> StateMBC a ()
> > splitAF pairBox e = case subUnitPos pairBox e of
>
>
> Your code was:
>
> > splitAF::(SubUnit a)=>BoxPair -> a -> StateMBC a ()
> > splitAF pairBox e = case subUnitPos pairBox (activeUnit e) of
>
>
> getUnitsOnPlane will compile if you comment out the type sig, but GHC
> generates this type sig:
>
>
> getUnitsOnPlane ::
>  (Unit su1 ~ Unit su,
>   SubUnit (ActiveSubUnit su),
>   SubUnit su1,
>   SubUnit su,
>   Ord su) =>
>  [Point]
>  -> BoxPair
>  -> t
>  -> StateT
>       (SubUnitsSets (ActiveSubUnit su))
>       Data.Functor.Identity.Identity
>       [Unit su]
>        -- Defined at DeUni.hs:324:1-15
>
> Note the class constraints are introducing a type variable *su1* that
> isn't mentioned in the function arguments, this strongly makes me
> think the function body isn't doing what it should. Also GHC infers a
> type var *t* rather than Plane for the second arg, again this makes me
> think the function body is not right.
>
> I'm a bit at a loss with the mbc function, if I comment out the
> function type sig and local type sigs GHC generates some errors
> mentioning Edge - as Edge is one of the instances of SubUnit, I think
> the function body is less polymorphic than you expect.
>
> Best wishes
>
> Stephen
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110327/eb8540e7/attachment-0001.htm>


More information about the Haskell-Cafe mailing list