[Haskell-beginners] Constructor classes and type classes.

PATRICK BROWNE patrick.browne at dit.ie
Fri Nov 4 00:10:26 UTC 2016


Imants
Thanks for the sanity check on the instances.

I am concerned about the use of the function immsucc' from the same paper
<http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.36.9395>, which is
defined in instances the Time class (but omitted from the class). The
function  immsucc' is first used without arguments, which to me implies
that it 'might' a function passed to the higher-order closure function. It
is then used as just an ordinary function with arguments. I have found a
version of closure based on Craft of Function Programming.
<https://github.com/buntine/Haskell--Craft-of-FP/blob/master/AbsTypes/Relation.lhs>
which
does not require a function as an argument.

So basically my question is: does the usage of immsucc' make sense in the
code below?, do the types match up?
Regards,
Pat



data TimeFacts t = Bef (t, t, TimeFacts t) | New

class SetClass t => Time l t where
 new :: (t, t) -> l t
 bef :: (t, t, l t) -> l t
 succ , pred :: (t, l t) -> Set t
 immsucc , immpred :: (t, l t) -> Set t
 before, after :: (t, t, l t) -> Bool
 immedbefore, immedafter :: (t, t, l t) -> Bool
 immedafter (a, b, t) = immedbefore (b, a, t)
 after (a, b, t) = before (b, a, t)
 before (a, b, t) = memberInSet (b, succ (a, t))
 succ (a, tl) = closure ([a], immsucc' , tl)
 pred (a, tl) = closure ([a], immpred' , tl)
 immsucc (a, tl) = immsucc' ([a], [], tl)
 immpred (a, tl) = immpred' ([a], [], tl)

instance (SetClass t) => Time TimeFacts t where
 immsucc’ (a, s, New ) = s
 immsucc’ (a, s, Bef (e, f, tt)) = if memberInSet (e,a) then immsucc’ (a,
insertInSet (f,s), tt) else immsucc’ (a, s,tt)


On 3 November 2016 at 18:05, Imants Cekusins <imantc at gmail.com> wrote:

> this builds. not sure if the instances are as intended
>
>
> {-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
> module SetClass where
>
> data TimeFacts t = Bef (t, t, TimeFacts t) | New
>
> class SetClass t  where
> class SetClass t => Time l t  where
> class Time l t => TimeE l t where
> class Time l t => TimeTO l t where
>
>
> instance SetClass (TimeFacts t) where -- OK
> instance (SetClass t) => Time (TimeFacts t) t where
> instance (SetClass t) => TimeE (TimeFacts t) t where
> instance (SetClass t) => TimeTO (TimeFacts t) t where
>
>>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>

-- 


This email originated from DIT. If you received this email in error, please 
delete it from your system. Please note that if you are not the named 
addressee, disclosing, copying, distributing or taking any action based on 
the contents of this email or attachments is prohibited. www.dit.ie

Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí 
earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an 
seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon 
dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa 
ríomhphost nó sna hiatáin seo. www.dit.ie

Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to 
Grangegorman <http://www.dit.ie/grangegorman>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20161104/24a37a6e/attachment.html>


More information about the Beginners mailing list