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:  replacing fold with scan! (Brent Yorgey)
   2. Re:  Problem installing EclipseFp in Eclipse (Vlatko Basic)


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

Message: 1
Date: Thu, 1 May 2014 13:00:28 -0400
From: Brent Yorgey <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] replacing fold with scan!
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Thu, May 01, 2014 at 12:31:38PM +0800, Zhi An Ng wrote:
> 
> So to get this to work, you need to change the type signature of filter''
> 
> filter'' :: (a -> Bool) -> [a] -> [[a]]

Well, but that is not filter, is it?  It is possible to define the
original filter using scanr, but you have to do a little
postprocessing of the output of scanr.

-Brent

> 
> 
> On Thu, May 1, 2014 at 10:42 AM, raffa f <[email protected]> wrote:
> 
> > hi everyone! here's my new problem. i wrote my version of filter:
> >
> > filter' :: (a -> Bool) -> [a] -> [a]
> > filter' f = foldr (\x acc -> if f x then x:acc else acc) []
> >
> > and it works! however, i wanted to use scan too. so i just replaced foldr
> > with scanr, to see what would happen:
> >
> > filter'' :: (a -> Bool) -> [a] -> [a]
> > filter'' f = scanr (\x acc -> if f x then x:acc else acc) []
> >
> > but that doesn't work! ghci gives me this:
> >
> > folds.hs:15:59:
> >     Couldn't match expected type `a' with actual type `[a0]'
> >       `a' is a rigid type variable bound by
> >           the type signature for filter'' :: (a -> Bool) -> [a] -> [a]
> >           at folds.hs:14:13
> >     In the second argument of `scanr', namely `[]'
> >     In the expression:
> >       scanr (\ x acc -> if f x then x : acc else acc) []
> >     In an equation for filter'':
> >         filter'' f = scanr (\ x acc -> if f x then x : acc else acc) []
> > Failed, modules loaded: none.
> >
> > the problem seems to be with the start value of [], it seems? i don't
> > understand, i thought scan and fold worked pretty much the same. i learned
> > about these functions today, so i'm still trying to wrap my head around
> > them...
> >
> > thank you!
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
> >
> >

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



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

Message: 2
Date: Thu, 01 May 2014 19:23:08 +0200
From: Vlatko Basic <[email protected]>
To: Robert Weisser <[email protected]>,  The Haskell-Beginners
        Mailing List - Discussion of primarily beginner-level topics related
        to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Problem installing EclipseFp in
        Eclipse
Message-ID: <[email protected]>
Content-Type: text/plain; charset="us-ascii"

An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140501/41003a5b/attachment.html>

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

Subject: Digest Footer

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


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

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

Reply via email to