Creating a GHC pre-FTP FTP server

For Haskell to teach beginners using the latest version of GHC, some function types may be confusing due to Foldable-Traversable-in-Prelude (FTP). For example, the basic functions in lists, such as length , sum and product , are of types that include the restriction Foldable foldr :: Foldable t => (a -> b -> b) -> b -> ta -> b . Similarly for some introductory functions of a higher order, for example. foldl :: Foldable t => (b -> a -> b) -> b -> ta -> b .

What is an easy way to temporarily enable pre-FTP mode? Then newbies can still take full advantage of the recent GHC and should not resort to installing older versions or using Hugs (for example, as suggested for edX FP101x 2015).

+6
source share
2 answers

This might work well, but we decided to go with something less tedious for http://haskellbook.com/ , which we did, we explained what had changed, and show them how you could approve the type based on the list.

 Prelude> :t length length :: Foldable t => ta -> Int Prelude> :t length :: [a] -> Int length :: [a] -> Int 

Meanwhile, with the types indicated in the examples and exercises, this was enough, and if they accidentally encounter a type with Foldable in it, this does not cause problems, because we told them how everything changed.

Forcing them to import things and not bother to tell them what happened seems fragile because they are embarrassed if they go off a happy journey.

+9
source

One of the options demonstrated the following:

 $ ghci Prelude> import Prelude hiding (length, sum, product, foldr, foldl, and, or, any, all) Prelude> import GHC.OldList Prelude GHC.OldList> 

Then you get old types for everything that was hidden, for example.

 length :: [a] -> Int sum :: Num a => [a] -> a product :: Num a => [a] -> a foldr :: (a -> b -> b) -> b -> [a] -> b foldl :: (b -> a -> b) -> b -> [a] -> b and :: [Bool] -> Bool any :: (a -> Bool) -> [a] -> Bool all :: (a -> Bool) -> [a] -> Bool 
+7
source

All Articles