Re: [Haskell-cafe] Deduce problem.

2011-11-21 Thread Ben Franksen
Magicloud Magiclouds wrote: > So I think I got what you guys meant, I limited ClassB to only H. > Then how to archive my requirement, that from and to only return items > that instanced ClassB? If you are willing to go beyond Haskell98 (or Haskell2010), you can use a multi-parameter class. Enable

Re: [Haskell-cafe] Deduce problem.

2011-11-17 Thread Magicloud Magiclouds
From the code, I think it is what I want. But still, I need some time to understand it Anyway, thank you. On Thu, Nov 17, 2011 at 4:02 PM, wrote: > > Multi-parameter type classes are more flexible. Here is how you can > write your old code: > >> {-# LANGUAGE MultiParamTypeClasses, FlexibleIn

Re: [Haskell-cafe] Deduce problem.

2011-11-17 Thread oleg
Multi-parameter type classes are more flexible. Here is how you can write your old code: > {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-} > > class (ClassA a, ClassB b) => ClassC a b where > from :: a -> [b] > to :: a -> [b] > > data H = H > > class ClassA a where toInt :: a -> I

Re: [Haskell-cafe] Deduce problem.

2011-11-16 Thread Magicloud Magiclouds
On Thu, Nov 17, 2011 at 1:17 PM, Brandon Allbery wrote: > On Wed, Nov 16, 2011 at 23:54, Magicloud Magiclouds > wrote: >> >> I think this is where I did not understand from the very beginning. >> If the the declaration was correct, then why cannot b be H? >> Referring to Data.List.genericLength,

Re: [Haskell-cafe] Deduce problem.

2011-11-16 Thread Brandon Allbery
On Wed, Nov 16, 2011 at 23:54, Magicloud Magiclouds < magicloud.magiclo...@gmail.com> wrote: > I think this is where I did not understand from the very beginning. > If the the declaration was correct, then why cannot b be H? > Referring to Data.List.genericLength, I was confused. Because it does

Re: [Haskell-cafe] Deduce problem.

2011-11-16 Thread MigMit
Of course, b can be H. The important question is: why can't it be something else? ClassC signature implies that b can be anything (of class ClassB) — not just H. Another error is that you declare from as returning a list, but you try to implement it as returning a single value. On 17 Nov 2011,

Re: [Haskell-cafe] Deduce problem.

2011-11-16 Thread Magicloud Magiclouds
I think this is where I did not understand from the very beginning. If the the declaration was correct, then why cannot b be H? Referring to Data.List.genericLength, I was confused. On Thu, Nov 17, 2011 at 12:34 PM, MigMit wrote: > You've declared "from" as forall b. Test -> [b], but you're tryin

Re: [Haskell-cafe] Deduce problem.

2011-11-16 Thread MigMit
You've declared "from" as forall b. Test -> [b], but you're trying to implement it as Test -> H. On 17 Nov 2011, at 07:48, Magicloud Magiclouds wrote: > Hi, > Consider I have declarations like this: > class (ClassA a) => ClassC a where > from :: (ClassB b) => a -> [b] > to :: (ClassB c) => a

Re: [Haskell-cafe] Deduce problem.

2011-11-16 Thread Magicloud Magiclouds
On Thu, Nov 17, 2011 at 11:48 AM, Magicloud Magiclouds wrote: > Hi, >  Consider I have declarations like this: > class (ClassA a) => ClassC a where >  from :: (ClassB b) => a -> [b] >  to :: (ClassB c) => a -> [c] > > data H = ... > > instance ClassB H where >  ... > > data Test = Test { m :: H }

[Haskell-cafe] Deduce problem.

2011-11-16 Thread Magicloud Magiclouds
Hi, Consider I have declarations like this: class (ClassA a) => ClassC a where from :: (ClassB b) => a -> [b] to :: (ClassB c) => a -> [c] data H = ... instance ClassB H where ... data Test = Test { m :: H } instance ClassA Test where ... instance ClassC Test where from = m to = m