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:  Adding 1 to Just 9 (Alex Belanger)
   2. Re:  Adding 1 to Just 9 (Alex Belanger)
   3.  Can't remove old haskell (Lawrence Bottorff)


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

Message: 1
Date: Mon, 14 May 2018 09:17:57 -0400
From: Alex Belanger <i.caught....@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Adding 1 to Just 9
Message-ID:
        <cadsky2xapj3z-_3+oayrt6dc_zm17tvi3lmseuyzaa88k01...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

A first approximative intuition is to think of Functors as containers (or
more like a context) and of fmap as a way to apply a transformation
function of your choice on the contained value, respecting the
signification of that context.

For example, Maybe represents the possibility of having or not having a
value, therefore, fmap will apply your transformation on that value if it
exists, otherwise you're still left with nothing.

This example might seem straight forward but it had to be defined
somewhere, thus, made possible by the Functor instance implementation for
the type Maybe.

Let's have a look at it:

fmap :: Functor f => (a -> b) -> f a -> f b

Specialized:

fmap ~ (a -> b) -> Maybe a -> Maybe b

And concretize further:

fmap ~ Num n => (n -> n) -> Maybe n -> Maybe n

As you can see, given a transformation function and maybe some numeral,
you'll get maybe another numeral.

The implementation lools like this:

fmap f (Just n) = Just (f n)
fmap f Nothing = Nothing

Thus, starting with Nothing, we cannot apply our tranformation so you stay
with Nothing. Similarly, with Just n, we're able to pattern match to obtain
that n, apply our transformation f on that n, and then rewrap everything
back into Just.

You can see how the value cannot escape its container / context.

Of course there are more complex such containers / context.

Either represents a choice between two values. [] contains multiple values,
IO contains (side-)effects, and so on.

Hope this helps.

nitrix

On Mon, May 14, 2018, 08:18 David McBride <toa...@gmail.com> wrote:

> let foo = \x -> Just (x + 1)
> fmap foo (Just 9)
>
> Just (Just 10)
>
>
> On Mon, May 14, 2018 at 8:15 AM, Olumide <50...@web.de> wrote:
>
>> Dear List,
>>
>> Chapter 14 of LYH appears to suggest that a Just value can be added to an
>> Int. Quote from
>> http://learnyouahaskell.com/for-a-few-monads-more#useful-monadic-functions
>>
>> "For instance, say we have Just 9 and the function \x -> Just (x+1). If
>> we map this function over Just 9, we're left with Just (Just 10)."
>>
>> I've tried the following in ghci but got the error:
>>
>> <interactive>:12:1: error:
>>     • Non type-variable argument in the constraint: Num (Maybe a)
>>       (Use FlexibleContexts to permit this)
>>     • When checking the inferred type
>>         it :: forall a. (Num (Maybe a), Num a) => Maybe a
>>
>>
>> Am I reading the quote wrong? Is Just (Just 10) a hypothetical?
>>
>> Regards,
>>
>> - Olumide
>> _______________________________________________
>> Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20180514/0963b212/attachment-0001.html>

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

Message: 2
Date: Mon, 14 May 2018 09:42:21 -0400
From: Alex Belanger <i.caught....@gmail.com>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell" <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Adding 1 to Just 9
Message-ID:
        <1526305341.1178196.1371365704.6a24c...@webmail.messagingengine.com>
Content-Type: text/plain; charset="utf-8"

Applicative is taking one step further, where the transformation itself
is also in such container/context.
<*> :: Functor => f (a -> b) -> f a -> f b
<*> ~ Maybe (a -> b) -> Maybe a -> Maybe b
<*> ~ Num n => Maybe (n -> n) -> Maybe n -> Maybe n

And the implementation:

(<*>) (Just f) (Just n) = Just (f n)
(<*>) Nothing (Just n) = Just n
(<*>) (Just f) Nothing = Nothing
(<*>) Nothing Nothing = Nothing

Thus, with everything we've learned, we should be able to deal with any
situation thrown at use, using Functor or Applicative.
Given (+1) and 42, I can basic function application with ($) or writing
it (+1) 42.Given (+1) and Just 42, I can use fmap to apply my transformation on
that functor, fmap (+1) (Just 42).Given Just (+1) and Just 42, I can use <*> to 
apply my transformation
inside a functor (applicative functor) to another functor, Just (+1)
<*> Just 42.Given Just (+1) and 42, I can wrap 42 with Just and again use <*> as
earlier, Just (+1) <*> Just 42.
Hope this helps.

nitrix

On Mon, May 14, 2018, at 9:17 AM, Alex Belanger wrote:
> A first approximative intuition is to think of Functors as containers
> (or more like a context) and of fmap as a way to apply a
> transformation function of your choice on the contained value,
> respecting the signification of that context.> 
> For example, Maybe represents the possibility of having or not having
> a value, therefore, fmap will apply your transformation on that value
> if it exists, otherwise you're still left with nothing.> 
> This example might seem straight forward but it had to be defined
> somewhere, thus, made possible by the Functor instance implementation
> for the type Maybe.> 
> Let's have a look at it:
> 
> fmap :: Functor f => (a -> b) -> f a -> f b
> 
> Specialized:
> 
> fmap ~ (a -> b) -> Maybe a -> Maybe b
> 
> And concretize further:
> 
> fmap ~ Num n => (n -> n) -> Maybe n -> Maybe n
> 
> As you can see, given a transformation function and maybe some
> numeral, you'll get maybe another numeral.> 
> The implementation lools like this:
> 
> fmap f (Just n) = Just (f n)
> fmap f Nothing = Nothing
> 
> Thus, starting with Nothing, we cannot apply our tranformation so you
> stay with Nothing. Similarly, with Just n, we're able to pattern match
> to obtain that n, apply our transformation f on that n, and then
> rewrap everything back into Just.> 
> You can see how the value cannot escape its container / context.
> 
> Of course there are more complex such containers / context.
> 
> Either represents a choice between two values. [] contains multiple
> values, IO contains (side-)effects, and so on.> 
> Hope this helps.
> 
> nitrix
> 
> On Mon, May 14, 2018, 08:18 David McBride <toa...@gmail.com> wrote:
>> let foo = \x -> Just (x + 1)
>> fmap foo (Just 9)
>> 
>> Just (Just 10)
>> 
>> 
>> On Mon, May 14, 2018 at 8:15 AM, Olumide <50...@web.de> wrote:
>>> Dear List,
>>> 
>>>  Chapter 14 of LYH appears to suggest that a Just value can be added
>>>  to an Int. Quote from
>>>  
>>> http://learnyouahaskell.com/for-a-few-monads-more#useful-monadic-functions>>>
>>>  
>>>  "For instance, say we have Just 9 and the function \x -> Just
>>>  (x+1). If we map this function over Just 9, we're left with Just
>>>  (Just 10).">>> 
>>>  I've tried the following in ghci but got the error:
>>> 
>>>  <interactive>:12:1: error:
>>>      • Non type-variable argument in the constraint: Num (Maybe a)
>>>        (Use FlexibleContexts to permit this)
>>>      • When checking the inferred type
>>>          it :: forall a. (Num (Maybe a), Num a) => Maybe a
>>> 
>>> 
>>>  Am I reading the quote wrong? Is Just (Just 10) a hypothetical?
>>> 
>>>  Regards,
>>> 
>>>  - Olumide
>>>  _______________________________________________
>>>  Beginners mailing list
>>> Beginners@haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>> 
>> _______________________________________________
>>  Beginners mailing list
>> Beginners@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20180514/e57cf46f/attachment-0001.html>

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

Message: 3
Date: Mon, 14 May 2018 12:52:01 -0400
From: Lawrence Bottorff <borg...@gmail.com>
To: beginners@haskell.org
Subject: [Haskell-beginners] Can't remove old haskell
Message-ID:
        <CAFAhFSWQ4dafK-U2KDbcvoqGV=9Jkuy0C-5OiG=-rwxvrsz...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I've followed the steps here
<https://www.haskell.org/platform/linux.html#linux-generic>; however, it
doesn't replace or supercede an older version of ghci from my Ubuntu 18.04:

12:47:02:~$ which ghci
/opt/ghc/8.0.2/bin/ghci
12:47:14:~$ ghci --version
The Glorious Glasgow Haskell Compilation System, version 8.0.2

I've tried various removes, but to no avail. The newer version is on my
system:

12:50:32:/usr/local/haskell/ghc-8.4.2-x86_64/bin$ ./ghci --version
The Glorious Glasgow Haskell Compilation System, version 8.4.2

But I don't know what to do about this old "default" version.

LB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20180514/8e5b9e83/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 119, Issue 6
*****************************************

Reply via email to