On 25 May 2016, at 2:43, Hamish Mackenzie wrote:
Thanks for another great podcast (as always).
We need to get you on sometime maybe :)
As mentioned in the podcast you can define a function that takes a homogenous list of 'a' where 'a' can be shown:
showAll :: Show a => [a] -> String showAll = concatMap show
One of the things I was meaning to make clear, but seemed to skip and then the moment past was that the list here IS homogenous as you say, and not heterogeneous. So when used the invocation is still working on say a List Person
, but enforced that there is an instance Show Person
available, you wouldn't be able to pass in a Person
and a Pet
if they were disparate types.
Now you can have entries in your list with different show functions:
> customShowAll [(show, [1..10]), (show . take 5, [1..])] "[1,2,3,4,5,6,7,8,9,10][1,2,3,4,5]"
Even here tho, a
is locked to a concrete type. Unless they were all part of say:
data FamilyMember = Person { name :: String, age :: Int }
| Pet { called :: String, breed :: String }
deriving Show
But then, the Show
instance covers the cases.
Correct?
--
Mark Derricutt
http://www.theoryinpractice.net
http://www.chaliceofblood.net
http://plus.google.com/+MarkDerricutt
http://twitter.com/talios
http://facebook.com/mderricutt