Wednesday, 15 January 2014

haskell - How to make constraints of class function depends from class instance? -


I'm playing with a wrapper for lists that can be indexed individually.

The basic class of such wrappers:

  class list where the list: :: - ->   

The cover of the index which can be indexed by integral

Data IdxByIntList ia = (Ix i, Integral i) = & gt; IdxByIntList {getList :: [a]}

If there is an example of IdxByIntList of list , then i Integral and Ix :

  Example (Integral I, Ix i) => The list (idxByIntList i) from where = list = getList  

looks like the indexed function in the constraint (Ix i, integral i) dissatisfied It is possible to do this in the IDX list indexed :

  example indexed IDXBIInLIS list where indexed = zip [0 ..] . GetList  

but it can not be compiled because the compiler type variable i to enum and Num .

Edit:

In the indexed for IdxByIntList , [0 ..] Code> (name, anonymous A) which goes to zip [0 ..] and so on and it goes to indexed . Therefore, should be bound to indexed (Ix I, Enum i, Num i, List (li)) but it is not.

An example of i is integral , so it is an example of Num and Enum .

I have common barriers to all indexed and there are additional constraints for this, which are dependent on solid examples. Here, I have to put IdxByIntList on the constraint (Ix i, list (i), integral i) on indexed . How can I do this?

About changing the class a bit

  {- # LANGUAGE typefile # -} Import data IECS indexed Li where indexed :: li ~ li = & gt; Li-A - & gt; [(I, A)] - I - Type of index - L - Type wrapper data IDXBIINLLITI AA = IDXIILLIL {getList :: [A]} Example (Integral I, IXI) = & gt; Indexed (IdxByIntList i) where indexed = zip [0 ..]. GetList  

This class creates the parameter only l instead of l , which may be sufficient for your use.

If you really need the do to be parametized on l , things will be more difficult; I think you need a related family type again * - & gt; Restrictions , which requires the constraintkinds extensions, and becomes odd to express family examples when more than one class obstacle is involved. (I do not know that this will work satisfactorily in practice.)


No comments:

Post a Comment