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:  Type declarations (Francesco Ariis)
   2. Re:  Type declarations (Patrik Iselind)
   3. Re:  Type declarations (Francesco Ariis)
   4. Re:  Why do i need to specify the class of a here at all?
      (Patrik Iselind)
   5. Re:  Type declarations (Patrik Iselind)
   6. Re:  Type declarations (Francesco Ariis)
   7. Re:  Type declarations (mrx)


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

Message: 1
Date: Sun, 26 Nov 2017 21:24:01 +0100
From: Francesco Ariis <fa...@ariis.it>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Type declarations
Message-ID: <20171126202401.jppfe6tmm67lf...@x60s.casa>
Content-Type: text/plain; charset=us-ascii

On Sun, Nov 26, 2017 at 07:39:49PM +0100, Patrik Iselind wrote:
> Does this mean that i can write `delta :: Point Double t -> Point Double t
> -> Direction d` as a type declaration. Then i would require `Coordinate
> Double Double` as in parameters. Correct?

Careful there! Let's take a simple data declaration

    data Point = Point Int Float

On the right you have *the type*, on the left you have *the (data)
constructor*.

When you are writing signatures you are writing types, so

    f :: Point -> Point

and not

    f :: Point Int Float -> Point Int Float

Much like you write `addition :: Int -> Int -> Int` and not
`addition :: 7 -> 2 -> 9`.


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

Message: 2
Date: Sun, 26 Nov 2017 22:21:39 +0100
From: Patrik Iselind <patrik....@gmail.com>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Type declarations
Message-ID: <d6445383-2ad4-6d53-5d02-bc94e0616...@gmail.com>
Content-Type: text/plain; charset=utf-8; format=flowed


Den 2017-11-26 kl. 21:24, skrev Francesco Ariis:
> On Sun, Nov 26, 2017 at 07:39:49PM +0100, Patrik Iselind wrote:
>> Does this mean that i can write `delta :: Point Double t -> Point Double t
>> -> Direction d` as a type declaration. Then i would require `Coordinate
>> Double Double` as in parameters. Correct?
> Careful there! Let's take a simple data declaration
>
>      data Point = Point Int Float
>
> On the right you have *the type*, on the left you have *the (data)
> constructor*.
But if the type Point have a parameter, `data Point p = Coordinate p p`. 
Then i must be able to tell which `p` when i use Point in a type 
declaration right? Like `delta :: Point Double a -> Point Double b -> 
Double` would say that p is Double. How else am i supposed to specify p 
in type declaration?

// Patrik


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

Message: 3
Date: Sun, 26 Nov 2017 22:41:35 +0100
From: Francesco Ariis <fa...@ariis.it>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Type declarations
Message-ID: <20171126214135.732pblhx4ouym...@x60s.casa>
Content-Type: text/plain; charset=us-ascii

On Sun, Nov 26, 2017 at 10:21:39PM +0100, Patrik Iselind wrote:
> But if the type Point have a parameter, `data Point p = Coordinate p p`.
> Then i must be able to tell which `p` when i use Point in a type declaration
> right? Like `delta :: Point Double a -> Point Double b -> Double` would say
> that p is Double. How else am i supposed to specify p in type declaration?

If the type has a parameter, like

    data Point a = Coordinates a a

it will specified *once* in the signature, like this:

    f :: Point Double -> Point Double -> String

implementation looking something like

    f (Coordinates x y) (Coordinates m q) = x + 7 -- etc. etc.


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

Message: 4
Date: Sun, 26 Nov 2017 22:46:29 +0100
From: Patrik Iselind <patrik....@gmail.com>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Why do i need to specify the class of
        a here at all?
Message-ID: <3baa5db0-8901-0029-1366-eb06e2359...@gmail.com>
Content-Type: text/plain; charset="utf-8"; Format="flowed"


Den 2017-11-26 kl. 20:48, skrev Quentin Liu:
>> ```
>> exercises.hs:33:13:
>>     Couldn't match expected type ‘[b0]’ with actual type ‘a’
>>       ‘a’ is a rigid type variable bound by
>>           the type signature for myOrderFunc :: a -> a -> Ordering
>>           at exercises.hs:31:16
>>     Relevant bindings include
>>       y :: a (bound at exercises.hs:32:15)
>>       x :: a (bound at exercises.hs:32:13)
>>       myOrderFunc :: a -> a -> Ordering (bound at exercises.hs:32:1)
>>     In the first argument of ‘myLen’, namely ‘x’
>>     In the first argument of ‘(<)’, namely ‘myLen x’
>> Failed, modules loaded: none.
>> ```
>
> Your guess is correct. The problem is, Haskell does not consider `a` 
> in `myOrderFunc` and `[b]` in `myLen` equivalent. `a` means you feed 
> the function any type, while `[b]` means it must be a list of values 
> of the same type. So changing `a` to `[a]` woud eliminate the error.
Thanks a lot for the clarification.

// Patrik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20171126/760c4d34/attachment-0001.html>

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

Message: 5
Date: Sun, 26 Nov 2017 22:51:26 +0100
From: Patrik Iselind <patrik....@gmail.com>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Type declarations
Message-ID: <fb39bc47-01fe-e366-1bb2-6b5fd2fb3...@gmail.com>
Content-Type: text/plain; charset=utf-8; format=flowed


Patrik Iselind

Den 2017-11-26 kl. 22:41, skrev Francesco Ariis:
> On Sun, Nov 26, 2017 at 10:21:39PM +0100, Patrik Iselind wrote:
>> But if the type Point have a parameter, `data Point p = Coordinate p p`.
>> Then i must be able to tell which `p` when i use Point in a type declaration
>> right? Like `delta :: Point Double a -> Point Double b -> Double` would say
>> that p is Double. How else am i supposed to specify p in type declaration?
> If the type has a parameter, like
>
>      data Point a = Coordinates a a
>
> it will specified *once* in the signature, like this:
>
>      f :: Point Double -> Point Double -> String
So what you're saying is that the `a` and `b` characters in my examples 
should not be there. Other than that it's correct?

// Patrik


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

Message: 6
Date: Sun, 26 Nov 2017 23:31:05 +0100
From: Francesco Ariis <fa...@ariis.it>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Type declarations
Message-ID: <20171126223104.btdjdyinmdvgp...@x60s.casa>
Content-Type: text/plain; charset=us-ascii

On Sun, Nov 26, 2017 at 10:51:26PM +0100, Patrik Iselind wrote:
> So what you're saying is that the `a` and `b` characters in my examples
> should not be there. Other than that it's correct?

Indeed :)


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

Message: 7
Date: Mon, 27 Nov 2017 09:01:19 +0100
From: mrx <patrik....@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Type declarations
Message-ID:
        <CANzOjBhDVfmyZDbyM=0cx3GHUS2-ZUTCRy1k0Nmqu8b8BXFC=g...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Den 26 nov 2017 23:32 skrev "Francesco Ariis" <fa...@ariis.it>:

On Sun, Nov 26, 2017 at 10:51:26PM +0100, Patrik Iselind wrote:
> So what you're saying is that the `a` and `b` characters in my examples
> should not be there. Other than that it's correct?

Indeed :)


Awesome, thanks a lot!

// Patrik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20171127/a0eff2ce/attachment.html>

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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 113, Issue 27
******************************************

Reply via email to