[Haskell-cafe] Re: [Haskell] ANN: random-access-list-0.1

Isaac Dupree isaacdupree at charter.net
Thu Jun 12 10:10:56 EDT 2008


Henning Thielemann wrote:
> 
> On Thu, 12 Jun 2008, Isaac Dupree wrote:
> 
>> Henning Thielemann wrote:
>>>
>>> On Wed, 11 Jun 2008, Isaac Dupree wrote:
>>>
>>>> "extractHead" is an ugly name for a nevertheless standardish-meaning 
>>>> function... what is it usually called? uncons? headTail? 
>>>> (Data.Sequence, which is meant to be left-right symmetric, calls it 
>>>> "viewr"... except your version doesn't have the Maybe, it's partial 
>>>> instead, fails on empty lists)
>>>
>>> I like the 'viewL' and 'viewR' kind of functions, they are safer than 
>>> 'head' and 'tail', 'init' and 'last'. But since in most cases I used 
>>> 'viewL' in connection with 'maybe', the continuation style functions
>>>
>>> switchL :: b -> (a -> Seq a -> b) -> Seq a -> b
>>> switchR :: b -> (Seq a -> a -> b) -> Seq a -> b
>>
>> I think you got L and R backwards?
> 
> Why do you think so?
> 
> http://cvs.haskell.org/Hugs/pages/libraries/base/Data-Sequence.html#v%3Aviewl 

Because I was confused.  Looking again, you seem to be right...

>> it's a little confusing to me, but following Data.Sequence I think 
>> they're meant to match whether repeated L or R makes a foldl or a foldr.
> 
> viewl is like a 'case' for distinction of [] and (:) and thus can be 
> used to implement both foldl and foldr.

yes, but in the sense that foldr is more "natural" for lists than foldl, 
requiring just replacing the constructors "directly"



More information about the Haskell-Cafe mailing list