[Haskell-cafe] Question, re: type class syntax.
David Banas
capn.freako at gmail.com
Sun Aug 30 01:07:09 UTC 2015
Thank you, both, for responding.
What I was trying to express was that the particular type of LogTree2, t, would determine the type of SizedVector, a, apropos to the ‘evaluator’ function, for a particular instance. It looks like functional dependencies is the right way to achieve this, because this type checks:
class LogTree2 t a | t -> a where
evaluator :: LogTree2 t a => t -> SizedVector a -> SizedVector a
-db
On Aug 29, 2015, at 5:39 PM, William Yager <will.yager at gmail.com> wrote:
> Hey David,
>
> I think there might be a bit of confusion here. When you say "LogTree2 a", that means "a" is an instance of "LogTree2". Maybe you want something like this?
>
> evaluator :: LogTree2 a => a -> SizedVector a -> SizedVector a
>
> Some context might help us to understand what you're going for.
>
> --Will
>
>
> On Sat, Aug 29, 2015 at 7:30 PM, David Banas <capn.freako at gmail.com> wrote:
> Thanks, Will.
> Maybe I’ve got the syntax all wrong, but my intent is just to constrain the type ’t’ to be of class 'LogTree2 a’.
> -db
>
> On Aug 29, 2015, at 5:27 PM, William Yager <will.yager at gmail.com> wrote:
>
>> If you want the "LogTree2" typeclass to have multiple type arguments (which it looks like you do, from the definition of "evaluator"), you need to define it as
>>
>> class (Show a, Num a) => LogTree2 a t where
>>
>> --Will
>>
>> On Sat, Aug 29, 2015 at 6:45 PM, David Banas <capn.freako at gmail.com> wrote:
>> Hi all,
>>
>> I can’t figure out why this is invalid:
>>
>> class (Show a, Num a) => LogTree2 a where
>> evaluator :: (LogTree2 a) t => t -> SizedVector a -> SizedVector a
>>
>> error| ‘LogTree2’ is applied to too many type arguments In the type ‘(LogTree2 a) t => t -> SizedVector a -> SizedVector a’ In the class declaration for ‘LogTree2’
>>
>> Can anyone help me understand?
>>
>> Thanks,
>> -db
>>
>>
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150829/c7c4ca86/attachment.html>
More information about the Haskell-Cafe
mailing list