[Haskell-beginners] Why doesn't ghci load this?

Brandon S. Allbery KF8NH allbery at ece.cmu.edu
Sat Mar 28 01:20:47 EDT 2009


On 2009 Mar 28, at 0:59, Jeff Lasslett wrote:
> myGroupBy :: (a -> a -> Bool) -> [a] -> [[a]]
> myGroupBy p xs =
> foldr step [[]] xs
> where
>  -- step :: a -> [ [ a ] ] -> [ [ a ] ]
>  step x acc@( ys : yss )
>   | null ys                      = [ x ] : []
>   | p x ( head ys )              = ( x : ys ) : yss
>   | ( p x ( head ys ) ) == False = [ x ] : acc

In Haskell98, the type "a" in step is not the same as the one in  
myGroupBy.  If you use the ScopedTypeVariables extension (see the ghc  
manual; just adding the option won't work) you can write the type.

-- 
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery at kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery at ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH


-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 195 bytes
Desc: This is a digitally signed message part
Url : http://www.haskell.org/pipermail/beginners/attachments/20090328/9849f6ad/PGP.bin


More information about the Beginners mailing list