Send Beginners mailing list submissions to
[email protected]
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
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: ap = liftM2 id (martin)
2. Re: ap = liftM2 id (Andres L?h)
3. Re: Maybe and Just (Greg Graham)
4. Re: ap = liftM2 id (Rein Henrichs)
5. Re: Maybe and Just (Shishir Srivastava)
----------------------------------------------------------------------
Message: 1
Date: Thu, 26 Mar 2015 22:48:37 +0100
From: martin <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] ap = liftM2 id
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Am 03/26/2015 um 09:33 PM schrieb Andres L?h:
I'll have to think about this. But other than that I am laughing my ass off
after reading your paper about "Konjunktiv
III". I can hardly type.
> There's no such thing as a fixed arity of a function in Haskell. The
> type of id is
>
>> id :: a -> a
>
> If you instantiate "a" with "b -> c", then it becomes
>
>> id :: (b -> c) -> b -> c
>
> and it suddenly takes two arguments. In fact, it then behaves like
> function application. Try
>
>> id not True
>
> or
>
>> not `id` True
>
> and you'll see that it works as if you had used function application
> or $ instead. So ap lifts function application, and if it helps, you
> can think of it as instead being defined as
>
>> ap = liftM2 ($)
>
> Cheers,
> Andres
>
>
> On Thu, Mar 26, 2015 at 9:18 PM, martin <[email protected]> wrote:
>> Hello all,
>>
>> can someone explain
>>
>> ap = liftM2 id
>>
>> to me? liftM2 wants a binary funcation
>>
>> liftM2 :: (Monad m) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r
>>
>> but id is unary. How does this work?
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
>
------------------------------
Message: 2
Date: Thu, 26 Mar 2015 23:19:20 +0100
From: Andres L?h <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] ap = liftM2 id
Message-ID:
<caljd_v4ohtkhftofwuqzc5_rfakk--+m97xse8cr14kqno-...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
> I'll have to think about this. But other than that I am laughing my ass off
> after reading your paper about "Konjunktiv
> III". I can hardly type.
Oh, that was written a long, long time ago. Glad you like it :)
Cheers,
Andres
------------------------------
Message: 3
Date: Thu, 26 Mar 2015 18:05:56 -0500
From: Greg Graham <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Maybe and Just
Message-ID:
<CAJdD3rtRCeyk=XUe+GE9_NQJzXc=Cik9ObmF5UuXXgNsDocZ=q...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8
On Thu, Mar 26, 2015 at 4:04 PM, martin <[email protected]> wrote:
> Am 03/26/2015 um 11:06 AM schrieb Shishir Srivastava:
>> Hi,
>>
>> After reading and re-reading the haskell tutorials I don't happen to see a
>> very convincing or appealing reason for
>> having these data types.
>>
>> Can anyone please explain where Maybe and Just provide the sort of
>> functionality that cannot be achieved in other
>> languages which don't have these kind.
I'm reading the little book, _Maybe Haskell_ [1], and I'm finding it
very helpful on this topic. The whole Maybe paradigm is one of the
reasons I decided to learn Haskell.
I had previously started learning Go, and although I was initially
attracted by its simplicity, I came to dislike how it used return
values to indicate errors. Go typically returns a pair of values from
operations that can fail. One value is the normal return value, and
the other is an error code. At first look, I thought it was similar to
Haskell's Maybe. However, after doing a little Go programming, I
realized there's a big difference. The error codes in Go can be
ignored, sometimes accidentally, but you can't ignore Haskell's Maybe.
Sure, it's possible to respond poorly, but you do have to respond, all
because (Just 42) is not the same thing as (42).
1: https://robots.thoughtbot.com/maybe-haskell-our-newest-book
------------------------------
Message: 4
Date: Thu, 26 Mar 2015 17:34:46 -0700
From: Rein Henrichs <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] ap = liftM2 id
Message-ID:
<CAJp6G8xCJdgofSuvx7rzTG_w8x+54n034=eeg+a-b1zouod...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Following up on Andres's explanation, we have
ap f x = liftM2 id mf ma -- definition of ap
= do { f <- mf; a <- ma; return (id f x) } -- definition of liftM2
= do { f <- mf; a <- ma; return (f x) } -- definition of id, f x
y = (f x) y
We can see that id applied to f gives f which is then applied to a.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150326/588c00e2/attachment-0001.html>
------------------------------
Message: 5
Date: Fri, 27 Mar 2015 09:44:22 +0000
From: Shishir Srivastava <[email protected]>
To: Corentin Dupont <[email protected]>
Cc: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Maybe and Just
Message-ID:
<cale5rtuw0igyek5wbtugg81dchua6drpsqbcl7jefok1rhs...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Sorry, but I still have some grudges so to say with the way 'Maybe' is
defined.
By definition '*Maybe*' takes a type parameter which I will denote here as '
*tp*' for the sake of clarity like below -
data Maybe tp = Just tp | Nothing
Therefore '*tp*' is not representing a value perse such as '3' or 'XYZ' etc
but a data type such as '*Int*', '*Char*' etc.
But when we have to create a data type of '*Maybe*' we write '*Just 3*' and
not '*Just Int*' or '*Just Char*' which is how it's defined in the
definition (i.e. '*Just tp*' ) .
It is this discrepancy in definition and the actual value creation which is
slightly troubling me.
Thanks,
Shishir
Shishir Srivastava
+44 (0) 750 127 5019
On Thu, Mar 26, 2015 at 5:31 PM, Corentin Dupont <[email protected]>
wrote:
> Not really, when you define the type "Maybe a":
>
> data Maybe a = Just a | Nothing
>
> Haskell is creating automatically two functions for you:
>
> Just :: a -> Maybe a
> Nothing :: Maybe a
>
> In the first case, you can think of "Just" and "Nothing" as a sort of tag
> identifying which element of the sum you have.
> It the second case it's a function, with the same name.
> A more informed person than me could say if they are indeed separated of
> if they are the same thing in GHC...
>
>
> On Thu, Mar 26, 2015 at 5:34 PM, Shishir Srivastava <
> [email protected]> wrote:
>
>> isn't that then cyclic dependency between 'Maybe' and 'Just' ...where the
>> first one is defined in terms of second and vice-versa...?
>>
>> Shishir
>>
>>
>> On Thu, Mar 26, 2015 at 3:48 PM, Corentin Dupont <
>> [email protected]> wrote:
>>
>>> Hi Shishir,
>>> I think that's a legitimate question.
>>>
>>> By writing
>>>
>>> data Maybe a = a | Nothing
>>>
>>> you are saying that the type of the left hand side of the = is the same
>>> that right hand side (you are defining a type basically).
>>> Also you can only sum things of the same type.
>>> So you are saying:
>>> type "Maybe a" = type "a"
>>> Which is wrong.
>>> That's why "a" should be wrapped into something:
>>> type of "Just a" is indeed "Maybe a".
>>>
>>> "Just" is a type constructor:
>>> Just :: a -> Maybe a
>>> It allows you to build the Maybe.
>>>
>>> Said that, "Just" is a vocabulary choice.
>>> Personally I prefer the name choices of OCaml, Rust, Scala etc.: Option
>>> a = None | Some a
>>>
>>>
>>>
>>> On Thu, Mar 26, 2015 at 4:26 PM, Shishir Srivastava <
>>> [email protected]> wrote:
>>>
>>>> ok..but what's with using the keyword 'Just' ? why cannot 'Maybe' be
>>>> defined like this
>>>>
>>>> data Maybe a = a | Nothing
>>>>
>>>> what's the point in having 'Just' keyword ?
>>>>
>>>> Shishir
>>>>
>>>>
>>>> On Thu, Mar 26, 2015 at 10:26 AM, Michael Alan Dorman <
>>>> [email protected]> wrote:
>>>>
>>>>> Shishir Srivastava <[email protected]> writes:
>>>>> > After reading and re-reading the haskell tutorials I don't happen to
>>>>> > see a very convincing or appealing reason for having these data
>>>>> > types.
>>>>>
>>>>> To be clear: Maybe is the data *type*. Just and Nothing are its data
>>>>> *constructors*.
>>>>>
>>>>> > Can anyone please explain where Maybe and Just provide the sort of
>>>>> > functionality that cannot be achieved in other languages which don't
>>>>> > have these kind.
>>>>>
>>>>> The functionality can be achieved in other languages, certainly. The
>>>>> question is whether the clarity and safety is also achieved.
>>>>>
>>>>> When I see (as a totally contrived example):
>>>>>
>>>>> fopen :: Maybe FileHandle
>>>>>
>>>>> I know that that function may not be able to return a FileHandle value
>>>>> all the time. The compiler will, in fact, nag me if I do not write the
>>>>> code that calls it in such a way that it acknowledges that possibility.
>>>>>
>>>>> When I see:
>>>>>
>>>>> FILE * fopen ( const char * filename, const char * mode );
>>>>>
>>>>> It is not immediately clear whether that can fail. Sure, we can make
>>>>> that inference, based on what we know about filesystems, etc., but the
>>>>> compiler is never going to complain if I ignore the possibility.
>>>>>
>>>>> In my experience, programmers in many languages end up resorting to
>>>>> convention to try and work around these sorts of ambiguities. Large
>>>>> projects have strategies for naming functions that try to pass along
>>>>> information out of band, or languages have a pervasive culture of
>>>>> "lint"
>>>>> tools that try to use heuristics to make up for what the type system
>>>>> doesn't make simple.
>>>>>
>>>>> That said, I know that doing Maybe sorts of things in languages that
>>>>> don't have, say, pattern matching, or the idea of a "failure monad",
>>>>> gets to be a drag very quickly---manually unwrapping things is at best
>>>>> awkward, having to re-wrap them just to unwrap them again in a sequence
>>>>> of computations quickly leads one to believe "it's just not worth
>>>>> it"---or you resort to exception handling, which has its own challenges
>>>>> to do well.
>>>>>
>>>>> Mike.
>>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Beginners mailing list
>>>> [email protected]
>>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150327/afe0f16c/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 81, Issue 66
*****************************************