[Haskell-beginners] Parametrizing [] as an instance of the Functor type class

bergey at alum.mit.edu bergey at alum.mit.edu
Wed Jan 6 14:58:33 UTC 2016


On 2016-01-05 at 08:33, Olumide <50295 at web.de> wrote:
> On 31/12/2015 13:06, Olumide wrote:
>> ... considering that Functor is defined as
>>
>> class Functor f
>  >    where fmap :: (a -> b) -> f a -> f b
>>
>
> Still on the subject, according to LYH, the above definition(?) is read 
> thusly: "fmap takes a function from one type as to another and a functor 
> value applied with one type and returns a functor value applied with 
> another type".
>
> So if list is "a part of the part of the Functor type class" (quoting 
> LYH) how am I to grok a list e.g. [1,2,3] as a "functor value applied to 
> a type"?

The type of [1,2,3] is [Int] (or possibly [Integer], [Float], [Double],
or similar).  We read [Int] as "list of Ints".  "List" is the instance
of Functor, Int is the type to which "list" is applied.

This may be easier to understand for types which are written prefix,
rather than [], which is written around Int.  "List Int" or "Maybe Int"
look like a function List or Maybe applied to the argument Int, except
that the capitalization reminds us that these are types, not values /
terms.

The section on kinds, may help here.  Kinds give us a formal syntax for
expressing things like "list takes a type as input and gives back a new
type".

bergey


More information about the Beginners mailing list