typeclass - Ambiguous type in Haskell type class -


i want use parametrized type class. below source code:

class (ccontext3d c k v) => cbuilder3d c k v     build3d :: c -> -> string -> hsl hlangjs hlangjs 

at compilation receive following error:

could not deduce (cbuilder3d c k0 v0) context: cbuilder3d c k v bound type signature for:    build3d :: cbuilder3d c k v =>                               c -> -> string -> hsl hlangjs hlangjs 

the following code works correctly:

class (ccontext3d c keycontext3d string) => cbuilder3d c     build3d :: c -> -> string -> hsl hlangjs hlangjs 

how possibly release instance of class depending k , v types?

suppose there call build3d. context of call, compiler has find proper instance. involves finding values variables c k v. however, type of build3d not mention k v, impossible find those.

more concretely, if had

instance cbuilder3d c k1 v1 ... instance cbuilder3d c k2 v2 ... 

their related build3d function have same type, , compiler has no way choose 1 of those.

possible solutions:

if possible, should use functional dependencies or type families state value of k , v determined other parameters. might case or not, depending on specific class.

otherwise, try enabling allowambiguoustypes , typeapplications, , keep ambiguous type around. however, @ every call, have specify types explicitly in build3d @t1 @t2 @t3 @t4 x1 x2 x3 t1,... types variables c k v. not terribly convenient.

another option make k,v appear in type proxy:

import data.proxy  class (ccontext3d c k v) => cbuilder3d c k v     build3d :: proxy k -> proxy v -> c -> -> string -> hsl hlangjs hlangjs 

now each call should build3d (proxy :: proxy k1) (proxy :: proxy v1) x1 x2 x3.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -