Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Constructor classes and type classes. (Dimitri DeFigueiredo)
   2. Re:  Constructor classes and type classes. (PATRICK BROWNE)
   3. Re:  Constructor classes and type classes. (Imants Cekusins)
   4. Re:  Java-Bridge, Ambiguous occurrence ‘<$’ (David McBride)


----------------------------------------------------------------------

Message: 1
Date: Thu, 3 Nov 2016 09:43:33 -0600
From: Dimitri DeFigueiredo <defigueir...@ucdavis.edu>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Constructor classes and type classes.
Message-ID: <80e94e0d-d05b-3606-290f-edcd7d8ef...@ucdavis.edu>
Content-Type: text/plain; charset=utf-8

Hi Patrick,

I am not sure I understand what you are trying to do, but here are some
thoughts.

- your use of the names `typeVar` and `typeCons` make total sense to me.
But your name `dataCons` in the definition of SetClass2 does not. You
are only talking about types here. All you are doing is talking about
*type* constructors. You are not constructing a specific value of that
type. Maybe one way to see the difference between the type constructors
and the data constructors is to change your first line to:

data SetType typeVar = SetTypeDataConstructor [typeVar] deriving Show

- I also don't understand why you named your type variable
`dataVariable` instead of sticking to `typeVar` in SetClass3. It is a
*type* variable in the type signature of the functions in the type class.

- I don't understand what you mean by a "constructor class". My simple
understanding of what a type constructors and data constructors are is here
https://wiki.haskell.org/Constructor#Type_constructor.

- I don't see the terms super class and sub class ever used in haskell
land. Although I do understand they make sense, I think they are really
OO terms. I've tried to map OO concepts into haskell and there are many
different ways to do it. The best description of all those ways that I
found was in Oleg Kiselyov's work
https://arxiv.org/pdf/cs/0509027.pdf

- I think parametric polymorphism as used in haskell forces us to
compare types in terms of equality constraints (this type is "the same"
as that), whereas subtype polymorphism as used in OO languages forces us
to think in terms of inequalities (this type is "more specific" than
that). I think those force fundamentally different ways to think about
and model your problems. I would encourage you to use equality as much
as possible, but if you want to model subtyping in haskell, I think
Oleg's work above has a few approaches that I think are better than type
classes. In particular, in OO there was always an ambiguity between
modelling subtyping with inheritance or with a "has a" relationship when
the subclass explicitly contains an object of the superclass. You can
use the latter idea in haskell, Oleg's work has a good way to do it.

Hope this helps.

Cheers,

Dimitri


> From: PATRICK BROWNE <patrick.bro...@dit.ie>
> To: The Haskell-Beginners Mailing List - Discussion of primarily
>       beginner-level topics related to Haskell <beginners@haskell.org>
> Subject: [Haskell-beginners] Constructor classes and type classes.
> Message-ID:
>       <CAGFLrKfQVaQQJybMTn-pJksV1VKUXrmBks14Jkm==Zqt=bd...@mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> {-
> I am trying to understand constructor classes and their relationship with
> ordinary type classes.
> I wrote the code below to help me understand the distinction. The code is
> only for explanatory purposes, set operations use a tuple syntax.
>
> I use the naming convention of 'typeVar', 'typeCons', and 'dataCons' for
> type variables, type constructors, and data constructors respectively.
> Question1:
> Is my naming convention correct?
> I am particularly concerned about SetClass3 where the super class seems to
> use a type constructor but the subclass seems to use the same term as a
> data constructor.
>
> Q2:
> In this case constructor classes and type classes seem to provide similar
> functionality.
> In general what situation are each best suited?
> -}
>
> import Data.List
> data SetType typeVar = SetType [typeVar] deriving Show
>
>
> class SetClass1 typeCons where
>   member1 ::   Eq typeVar  =>  (typeVar, typeCons typeVar)  -> Bool
>   intersect1 ::  (Eq typeVar,Show typeVar) =>  (typeCons typeVar, typeCons
> typeVar) -> typeCons typeVar
>
>
> class  SetClass2 dataCons typeVar where
>   member2 ::  (typeVar, (dataCons typeVar))  -> Bool
>   intersect2 :: (dataCons typeVar, dataCons typeVar) -> dataCons typeVar
>
>
> class SetClass1 typeCons => SetClass3  typeCons dataVariable where
>  union3 ::  (Eq dataVariable,Show dataVariable) =>  (typeCons dataVariable,
> typeCons dataVariable) -> typeCons dataVariable
>
> instance SetClass1 SetType where
>  member1 (x ,(SetType y)) = elem  x y
>  intersect1 ((SetType x),(SetType y)) = SetType (intersect x y)
>
> instance SetClass2 SetType Int where
>  member2 (x ,SetType y) =   elem  x y
>  intersect2 (SetType x,SetType y) = SetType (intersect x y)
>
> instance SetClass3 SetType Int where
>  union3 (SetType x,SetType y) = SetType (union x y)
>
>
> test1a = member1 (1, (SetType [1,2]))
> test1b = intersect1 ((SetType [1,3,4]),(SetType [1,2]))
> test2a = member2 (1, (SetType [1::Int]))
> test2b = intersect2 ((SetType [1::Int]), (SetType [(1::Int)]))
> test3a = union3 ((SetType [1::Int,2::Int,3::Int]),(SetType [4::Int,5::Int]))
>

-- 
2E45 D376 A744 C671 5100 A261 210B 8461 0FB0 CA1F


-- 
2E45 D376 A744 C671 5100 A261 210B 8461 0FB0 CA1F


------------------------------

Message: 2
Date: Thu, 3 Nov 2016 17:51:14 +0000
From: PATRICK BROWNE <patrick.bro...@dit.ie>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Constructor classes and type classes.
Message-ID:
        <cagflrkcdpcpzboxy2rxmxlmmnme5w+yhoe2cxpd3qentey4...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Dimitri,
Thanks for taking the time and effort to respond. Your comments have
clarified some of my confusion. My motivation is that I am trying to
implement the code from a paper
<http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.36.9395> with the
following data and classes:

{-# LANGUAGE MultiParamTypeClasses #-}
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

However I cannot get the instances to compile:
instance SetClass (TimeFacts t) where -- OK
instance (SetClass t) => Time TimeFacts t where -- Expecting one more
argument to 'TimeFacts'
instance TimeE TimeFacts t where -- Expecting one more argument to
'TimeFacts'
instance TimeTO TimeFacts t where -- Expecting one more argument to
'TimeFacts'


Note, I am only using the headings for the classes and instances, which
should be OK.
Any pointers to a solution would be much appreciated.

Regards,
Pat

-- 


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/20161103/e196c362/attachment-0001.html>

------------------------------

Message: 3
Date: Thu, 3 Nov 2016 19:05:10 +0100
From: Imants Cekusins <ima...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Constructor classes and type classes.
Message-ID:
        <cap1qinagvo+x5vzmr4gju8emjdt8pec5-r0apsr5s1g1ysn...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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

​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20161103/cb290551/attachment-0001.html>

------------------------------

Message: 4
Date: Thu, 3 Nov 2016 15:58:01 -0400
From: David McBride <toa...@gmail.com>
To: Desonte Jolivet <jolivetdeso...@yahoo.com>,  The Haskell-Beginners
        Mailing List - Discussion of primarily beginner-level topics related
        to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Java-Bridge, Ambiguous occurrence
        ‘<$’
Message-ID:
        <can+tr42vjsmr56wygzdmj7msv+ocsmchgbawou_bxg1gq52...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

That specific error can be fixed by simply removing that function and its
export from src/Foreign/Java/Util.hs as it is exported by Prelude now and
there is no reason for it to be in his code.

Given the amount of bitrot that package has probably suffered, I'm not sure
how much faith I have that it will work.  That said, if you are
enterprising it probably wouldn't be too hard to fix all these errors.

In other news there are some other recent developments on this front.
There is an inline-java project that looks very promising and may actually
be very simple to get up and working with stack.

https://github.com/tweag/inline-java#readme

On Thu, Nov 3, 2016 at 12:49 AM, Desonte Jolivet <jolivetdeso...@yahoo.com>
wrote:

> Hello All:
>
> Im interested interfacing with the JVM through Haskell and I found this
> neat library on Hackag name java-bridge although when I try and install
> with cabal I get the below error, "Ambiguous occurrence ‘<$’". Any tips on
> how to clear this up or how I should proceed would be very helpful, Thank
> you all in advance.
>
> src/Foreign/Java/IO.hs:5:7: Warning:
>     -XOverlappingInstances is deprecated: instead use per-instance pragmas
> OVERLAPPING/OVERLAPPABLE/OVERLAPS
> [ 1 of 24] Compiling Foreign.Java.Tutorial ( src/Foreign/Java/Tutorial.hs,
> dist/build/Foreign/Java/Tutorial.o )
> [ 2 of 24] Compiling Foreign.Java.IO  ( src/Foreign/Java/IO.hs,
> dist/build/Foreign/Java/IO.o )
> [ 3 of 24] Compiling Foreign.Java.Control ( src/Foreign/Java/Control.hs,
> dist/build/Foreign/Java/Control.o )
> [ 4 of 24] Compiling Foreign.Java.Bindings.ReflectHaskell (
> src/Foreign/Java/Bindings/ReflectHaskell.hs, 
> dist/build/Foreign/Java/Bindings/ReflectHaskell.o
> )
> [ 5 of 24] Compiling Foreign.Java.Bindings.Haskell2Java (
> dist/build/Foreign/Java/Bindings/Haskell2Java.hs, 
> dist/build/Foreign/Java/Bindings/Haskell2Java.o
> )
> [ 6 of 24] Compiling Foreign.Java.Bindings.HaskellTypes (
> src/Foreign/Java/Bindings/HaskellTypes.hs, 
> dist/build/Foreign/Java/Bindings/HaskellTypes.o
> )
> [ 7 of 24] Compiling Foreign.Java.Bindings.JavaSE6 (
> src/Foreign/Java/Bindings/JavaSE6.hs, 
> dist/build/Foreign/Java/Bindings/JavaSE6.o
> )
> [ 8 of 24] Compiling Foreign.Java.Utils ( src/Foreign/Java/Utils.hs,
> dist/build/Foreign/Java/Utils.o )
> [ 9 of 24] Compiling Foreign.Java.Bindings.JavaTypes (
> src/Foreign/Java/Bindings/JavaTypes.hs, 
> dist/build/Foreign/Java/Bindings/JavaTypes.o
> )
> [10 of 24] Compiling Foreign.Java.Util ( src/Foreign/Java/Util.hs,
> dist/build/Foreign/Java/Util.o )
>
> src/Foreign/Java/Util.hs:5:19:
>     Ambiguous occurrence ‘<$’
>     It could refer to either ‘Foreign.Java.Util.<$’,
>                              defined at src/Foreign/Java/Util.hs:24:1
>                           or ‘Prelude.<$’,
>                              imported from ‘Prelude’ at
> src/Foreign/Java/Util.hs:4:8-24
>                              (and originally defined in ‘GHC.Base’)
> cabal: Error: some packages failed to install:
> java-bridge-0.20130606.3 failed during the building phase. The exception
> was:
> ExitFailure 1
>
>
> -Jo
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20161103/41d7d526/attachment.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 101, Issue 4
*****************************************

Reply via email to