In addition to what Hal said,

I think that even assuming that you want to write a function like that
that is only supposed to be applied to finite lists (like, say,
prelude's 'and' function, which does not terminate on an infinite list
of True values) you still cannot do it because haskell lists are not
like C lists.

There is no notion, to my understanding, of list circularity. There are
finite and infinite lists. Your example of a list that you call a
circular list is just a definition of a recursive function that produces
an infinite list.

So what you are almost asking is how to write a function that checks if
a list has repeated sub-sequences, which is not of course precisely the
same that you asked (because even a finite list can have repeated
sub-sequences), but close. And this is just one of many problems taken
care of by various string search algorithms.

konst

> -----Original Message-----
> From: Hal Daume III [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, April 24, 2002 12:38 PM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: Re: lazy comparison for equality ?
> 
> 
> I don't think you can write such a function.  For instance, 
> how would you
> know whether [1..] is circular or not?  In order to know that it's not
> you'd need to evaluate it fully.
> 
> --
> Hal Daume III
> 
>  "Computer science is no more about computers    | [EMAIL PROTECTED]
>   than astronomy is about telescopes." -Dijkstra | www.isi.edu/~hdaume
> 
> On Wed, 24 Apr 2002 [EMAIL PROTECTED] wrote:
> 
> > 
> > Hi -
> > I'm a Haskell beginner and I have a problem. 
> > 
> > Let's have a list which may be normal list
> > list1 = [1,2,3]
> > or a circular list
> > list2 = 1:2:list2
> > 
> > Now I'd like to have a function which tells me whether the 
> > given list is circular or not. This doesn't work:
> > 
> > circ l = l l
> > circ2 l [] = False
> > circ2 l (_:as) | l==as = True
> >                | True = (circ2 l as)
> > 
> > 
> > It seems that comparison l==as really compares element by 
> element thus
> > falling into an infinite loop. I would need to compare 
> pointers instead of
> > values.
> > 
> > Does anybody know how this could be done ?
> > 
> > Thanks.
> > 
> > 
> > 
> > 
> > 
> > _______________________________________________
> > Haskell-Cafe mailing list
> > [EMAIL PROTECTED]
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> > 
> 
> _______________________________________________
> Haskell-Cafe mailing list
> [EMAIL PROTECTED]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
> 
_______________________________________________
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to