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. Equality error (PATRICK BROWNE)
2. Re: Help with improving a program (Florian Gillard)
----------------------------------------------------------------------
Message: 1
Date: Thu, 10 Jul 2014 13:38:00 +0100
From: PATRICK BROWNE <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Equality error
Message-ID:
<cagflrkdta79j2+ej80+cxj8hg6dxodo4bbdv7u8hssqj3ty...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
{-
Hi,
I am trying to get some Haskell code to run from a research paper[1]
The relevant fragment is shown below. The issue is that I cannot get the
code to run using the original Eq instance.
I have replaced the Eq instance with a set of deriving statements on the
data types and this works fine.
But I am anxious to know why I get the error when using the original code.
Also, it seems reasonable to be able to define equality based on names.
With the original Eq Instance I get the following error:
Context reduction stack overflow;...
In the expression: elem car cars
In an equation for `element': element car cars = elem car cars
In the instance declaration for `Collection Cars Car'
I am not too sure how to interpret this message.
Any clarification of the error and possible fix would be appreciated.
Thanks,
Pat
[1] ifgi.uni-muenster.de/~sumitsen/sen_Font05.pdf
-}
{-# LANGUAGE MultiParamTypeClasses,
FlexibleInstances,FunctionalDependencies,
TypeSynonymInstances,UndecidableInstances,TypeSynonymInstances
,OverlappingInstances #-}
import Data.List
class Collection collection single where
empty :: collection
addOne :: single -> collection -> collection
remove :: single -> collection -> collection
element :: single -> collection -> Bool
doToAll :: (single -> single) -> collection -> collection
class Named object name | object -> name where
name :: object -> name
-- **** in original code ****
-- All named objects can be compared for equality if names can
instance (Eq name, Named object name) => Eq object where
object1 == object2 = (name object1) == (name object2)
-- could add (Eq, Show) here
data Edge = Edge Node Node deriving Show -- (Eq, Show)
type Name = [Char]
data Node = Node Name deriving Show -- (Eq, Show)
data Car = Car Node deriving Show -- (Eq, Show)
type Cars = [Car]
instance Named Car Name where
name c = "a"
instance Collection Cars Car where
empty = [] -- ::Cars
addOne car cars = car:cars
remove car cars = delete car cars
element car cars = elem car cars
doToAll f cars = map f cars
-- addOne (Car (Node "a")) [Car (Node "a")]
-- addOne (Car (Node "a")) []::Cars
-- addOne (Car (Node "b")) [(Car (Node "a"))]
-- remove (Car (Node "a")) (addOne (Car (Node "b")) [(Car (Node "a"))])
--
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://www.haskell.org/pipermail/beginners/attachments/20140710/c11277e2/attachment-0001.html>
------------------------------
Message: 2
Date: Thu, 10 Jul 2014 15:24:44 +0200
From: Florian Gillard <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Help with improving a program
Message-ID:
<caglpzluzga8zxnwqmn27+ni1v7fnpdpx+cfguislusbkop3...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I don't know if this is any good but here is my attempt to solve this.
I used comprehensions.
It seems to be working fine with the test files :)
On Thu, Jul 10, 2014 at 11:35 AM, Frerich Raabe <[email protected]> wrote:
> On 2014-07-10 11:24, Francesco Ariis wrote:
>
>> On Wed, Jul 09, 2014 at 11:02:14PM -0300, Marcelo Lacerda wrote:
>>
>>> Hi I'm just starting with haskell and want some help with it.
>>>
>>> I tried to solve the Store Credit[1] problem from google code jam just
>>> to practice, the result was a slow code[2] that I find hard to read.
>>>
>>> Can you guys give me some directions on how to improve it?
>>>
>>> [1] - https://code.google.com/codejam/contest/351101/dashboard#s=p0
>>> [2] - http://pastebin.com/jNGxGP5H
>>>
>>>
>> Don't know about efficiency, but I never liked (!!). Maybe computing all
>> pairs+positions in advance using |zip| would be a little better?
>>
>
> Yeah, that's what I went for as well. I'm attaching my solution for
> comparison to this mail.
>
>
> --
> Frerich Raabe - [email protected]
> www.froglogic.com - Multi-Platform GUI Testing
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140710/3db2e882/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: credit.hs
Type: text/x-haskell
Size: 1005 bytes
Desc: not available
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140710/3db2e882/attachment-0001.hs>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 73, Issue 7
****************************************