Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Parametrizing [] as an instance of   the     Functor type
      class (ber...@alum.mit.edu)
   2. Re:  Parametrizing [] as an instance of   the     Functor type
      class (ber...@alum.mit.edu)


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

Message: 1
Date: Wed, 06 Jan 2016 09:50:42 -0500
From: ber...@alum.mit.edu
To: Olumide <50...@web.de>, beginners@haskell.org
Subject: Re: [Haskell-beginners] Parametrizing [] as an instance of
        the     Functor type class
Message-ID:
        
<87h9iqrccd.fsf@wonderlust.i-did-not-set--mail-host-address--so-tickle-me>
        
Content-Type: text/plain

On 2016-01-05 at 08:59, Olumide <50...@web.de> wrote:
> On 01/01/2016 19:41, Alexander Berntsen wrote:
>> Here we use [] both on type and term level. On type level we use it to
>> mean a list of 'a's, and on term level we use it to mean the empty list.
>
> Out of curiosity, is [] defined as type constructor _and_ term level at 
> the library level or in the language/compiler? (BTW, google tells me 
> "term-level" has a special meaning that I do not yet know.)

The special syntax of [] requires that the compiler (specifically, the
parser) treat lists specially.

We could define our own data type that behaves like lists,

List a = Nil | Cons a (List a)

but writing out literal lists would be a little clunky.  It's nice that
we can write:

[]
[1]
[1,2,3]

instead of:

Nil
Cons 1 Nil
Cons 1 (Cons 2 (Cons 3 Nil))

The [1,2,3] syntax requres that the Haskell parser be aware of this
type.

At the type level, we can write [Int], [Char], and so forth, instead of
List Int, List Char.  This also requires support in the parser.

bergey


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

Message: 2
Date: Wed, 06 Jan 2016 09:58:33 -0500
From: ber...@alum.mit.edu
To: Olumide <50...@web.de>, beginners@haskell.org
Subject: Re: [Haskell-beginners] Parametrizing [] as an instance of
        the     Functor type class
Message-ID:
        
<87egdurbza.fsf@wonderlust.i-did-not-set--mail-host-address--so-tickle-me>
        
Content-Type: text/plain

On 2016-01-05 at 08:33, Olumide <50...@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


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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 91, Issue 10
*****************************************

Reply via email to