Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

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


Today's Topics:

   1. Re:  Return a Foldable instance (Ozgur Akgun)
   2. Re:  Return a Foldable instance (Stephen Tetley)
   3. Re:  Return a Foldable instance (Antoine Latter)
   4. Re:  Return a Foldable instance (Felipe Almeida Lessa)
   5. Re:  Return a Foldable instance (Federico Mastellone)
   6. Re:  Return a Foldable instance (Federico Mastellone)
   7.  Haskell GUI library (Nathan H?sken)


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

Message: 1
Date: Wed, 4 May 2011 11:10:04 +0100
From: Ozgur Akgun <[email protected]>
Subject: Re: [Haskell-beginners] Return a Foldable instance
To: Federico Mastellone <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

On 4 May 2011 07:25, Federico Mastellone <[email protected]> wrote:

> Because the underlying structure is already Foldable, so why creating
> a dummy function for every method on the Foldable class that only
> calls the same function but in the underlying structure.


If you make your MultiMap type and instance of Foldable, you get *every
method on the Foldable class* for free anyway. Namely, you do not need to
replicate functions with a Foldable constraint with your MultiMap data type.

HTH,

--
Ozgur Akgun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110504/1cfb9c50/attachment-0001.htm>

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

Message: 2
Date: Wed, 4 May 2011 11:46:10 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Return a Foldable instance
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

I don't think anyone's pointed it out, but you can't build a Foldable
structure with just Foldable.

The Foldable class only allows you to "reduce" objects that already exist.


For instance you cannot write this function where the Map is Data.Map
rather than your MultiMap:

getValues :: Foldable f => k -> Data.Map k v -> f v


Really all you can do is produce an API like Data.Map, Data.Set have:

toList :: MultiMap k v -> [(k,v)]
toMap  :: Ord k => MultiMap k v -> Map k v
toSet  :: (Ord k, Ord v) => MultiMap k v -> Set (k,v)


In a nutshell, you seem to be wanting "container oblivious code". You
can't really do this in Haskell I'm afraid. You can traverse and
reduce containers generically with the Traverse and Foldable classes
but you can't build them generically[*].

Best wishes

Stephen


[*] This might not be a disadvantage once you get over the initial
disappointment - usually when you build something, you really do need
to know what it is.



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

Message: 3
Date: Wed, 4 May 2011 06:32:48 -0500
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] Return a Foldable instance
To: Federico Mastellone <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

On May 4, 2011 1:33 AM, "Federico Mastellone" <[email protected]> wrote:
>
> Sorry, the function type was incorrect, is for a part of the multimap,
> not the entire multimap. But it's the same problem, a function that
> returns a Foldable.
>
> getValues :: Foldable f => k -> MultiMap k v -> f v
>
> When the user asks for the values that a certain key contains I want
> to return something that is generic and easy to play with while also
> taking advantages of the underlying structure functions to avoid
> repeated code.

Well, "generic and easy to play with" is pretty much the definition of a
list.

If the only thing the caller is doing with the list is folding over it, the
compiler should get rid of the intermediary list anyway, if things work out
right.

So I think you're worrying too soon.

But if this something you want to do anyway, I still don't see what is wrong
with:

> newtype LookupResult a = L [a]
>     deriving (Foldable)

Then when you change your implementation of the multimap you can change your
newtype without affecting the caller.

Antoine

>
> On Wed, May 4, 2011 at 2:51 AM, Chadda? Fouch? <[email protected]>
wrote:
> > On Wed, May 4, 2011 at 7:18 AM, Federico Mastellone <[email protected]>
wrote:
> >> Yes, I got confused between haskell type classes and OO classes.
> >>
> >> I want to create different implementations of a multimap, for example
> >> using lists and using Data.Set, and instead of providing functions
> >> getValuesList and getValuesSet that return a [] and a Set respectively
> >> I want to provide a more generic one, getValues that returns a
> >> Foldable and avoid unnecessary conversions to and from lists. This way
> >> the user folds directly the underlying structure, without having to
> >> worry about which function is the best to fold the values. But I don't
> >> know how to do this without an extra intermediate data type.
> >>
> >> One implementation returns a list and the other a set, both Foldables.
> >> But I can't make a function like the one below for this two
> >> getValues :: Foldable f => MultiMap k v -> f v
> >>
> >
> > Writing this function given your intention (doing different thing
> > depending on the type) is equivalent to writing an instance of
> > Foldable for your (MultiMap k). If the underlying structure of your
> > multimaps is always foldable, it doesn't make sense to make a function
> > like this, the multimaps themselves should be Foldable. This is not
> > hard to do, refer to the doc (
> >
http://www.haskell.org/ghc/docs/7.0-latest/html/libraries/base-4.3.1.0/Data-Foldable.html
> > ) to see how to write a minimal instance of Foldable.
> >
> > --
> > Jeda?
> >
>
>
>
> --
> Federico Mastellone
> Computer Science Engineer - ITBA
> ".. there are two ways of constructing a software design: One way is
> to make it so simple that there are obviously no deficiencies, and the
> other way is to make it so complicated that there are no obvious
> deficiencies. The first method is far more difficult."
>
> Tony Hoare, 1980 ACM Turing Award Lecture.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20110504/cee04878/attachment-0001.htm>

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

Message: 4
Date: Wed, 4 May 2011 08:39:26 -0300
From: Felipe Almeida Lessa <[email protected]>
Subject: Re: [Haskell-beginners] Return a Foldable instance
To: Chadda? Fouch? <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Wed, May 4, 2011 at 2:51 AM, Chadda? Fouch? <[email protected]> wrote:
> Writing this function given your intention (doing different thing
> depending on the type) is equivalent to writing an instance of
> Foldable for your (MultiMap k). If the underlying structure of your
> multimaps is always foldable, it doesn't make sense to make a function
> like this, the multimaps themselves should be Foldable. This is not
> hard to do, refer to the doc (
> http://www.haskell.org/ghc/docs/7.0-latest/html/libraries/base-4.3.1.0/Data-Foldable.html
> ) to see how to write a minimal instance of Foldable.

I second this.  I don't see how an instance of Foldable (MultiMap k)
is different of what the OP wants.  Much easier and nicer.

Cheers,

-- 
Felipe.



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

Message: 5
Date: Wed, 4 May 2011 09:11:50 -0300
From: Federico Mastellone <[email protected]>
Subject: Re: [Haskell-beginners] Return a Foldable instance
To: Ozgur Akgun <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

The MultiMap is based on Foldable types, but it's not Foldable (at
least there's no need to).
I made a mistake with the example function, the type I want is
getValues :: Foldable f => k -> MultiMap k v -> f v
but I don't know how to return a generic Foldable type.

On Wed, May 4, 2011 at 7:10 AM, Ozgur Akgun <[email protected]> wrote:
> On 4 May 2011 07:25, Federico Mastellone <[email protected]> wrote:
>>
>> Because the underlying structure is already Foldable, so why creating
>> a dummy function for every method on the Foldable class?that only
>> calls the same function but in the underlying structure.
>
> If you make your MultiMap type and instance of Foldable, you get every
> method on the Foldable class for free anyway. Namely, you do not need to
> replicate functions with a Foldable constraint with your MultiMap data type.
> HTH,
> --
> Ozgur Akgun



-- 
Federico Mastellone
Computer Science Engineer - ITBA
".. there are two ways of constructing a software design: One way is
to make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."

Tony Hoare, 1980 ACM Turing Award Lecture.



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

Message: 6
Date: Wed, 4 May 2011 09:21:00 -0300
From: Federico Mastellone <[email protected]>
Subject: Re: [Haskell-beginners] Return a Foldable instance
To: Stephen Tetley <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

So, is it even possible to write a function with this type: getValues
:: Foldable f => k -> MultiMap k v -> f v ???

On Wed, May 4, 2011 at 7:46 AM, Stephen Tetley <[email protected]> wrote:
> I don't think anyone's pointed it out, but you can't build a Foldable
> structure with just Foldable.
>
> The Foldable class only allows you to "reduce" objects that already exist.
>
>
> For instance you cannot write this function where the Map is Data.Map
> rather than your MultiMap:
>
> getValues :: Foldable f => k -> Data.Map k v -> f v
>
>
> Really all you can do is produce an API like Data.Map, Data.Set have:
>
> toList :: MultiMap k v -> [(k,v)]
> toMap ?:: Ord k => MultiMap k v -> Map k v
> toSet ?:: (Ord k, Ord v) => MultiMap k v -> Set (k,v)
>
>
> In a nutshell, you seem to be wanting "container oblivious code". You
> can't really do this in Haskell I'm afraid. You can traverse and
> reduce containers generically with the Traverse and Foldable classes
> but you can't build them generically[*].
>
> Best wishes
>
> Stephen
>
>
> [*] This might not be a disadvantage once you get over the initial
> disappointment - usually when you build something, you really do need
> to know what it is.
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
Federico Mastellone
Computer Science Engineer - ITBA
".. there are two ways of constructing a software design: One way is
to make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."

Tony Hoare, 1980 ACM Turing Award Lecture.



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

Message: 7
Date: Wed, 04 May 2011 16:06:33 +0200
From: Nathan H?sken <[email protected]>
Subject: [Haskell-beginners] Haskell GUI library
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hey,

looking on the haskell homepage, there are a lot of gui libraries (or at
least bindings) available.
One big difference seems to be that some are based on "Functional
Reactive Programming" (I do not know what that is, just read it).

So if I want to write a gui in haskell, which library should I use?
Which is stable enough? Has anyone experience with some of these gui
libraries?

Thanks!
Nathan



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

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 35, Issue 7
****************************************

Reply via email to