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.  'Simple' function (Mike Houghton)
   2. Re:  'Simple' function (Steven Williams)
   3. Re:  'Simple' function (Brandon Allbery)
   4. Re:  'Simple' function (aldiyen)
   5. Re:  'Simple' function (Brandon Allbery)
   6. Re:  'Simple' function (Imants Cekusins)


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

Message: 1
Date: Wed, 10 Jun 2015 17:35:05 +0100
From: Mike Houghton <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] 'Simple' function
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8

Hi,

I?ve been tryimg to write a function  with signature

asString :: IO String -> String


Does someone please have the patience to explain to me what the compiler error 
messages really mean for these two attempts and exactly what I?m doing (!!!)
If I *do not* give this function any type signature then it works i.e..

asString ioStr = do 
    str <- ioStr
    return $ str

and the compiler tells me its signature is

asString :: forall (m :: * -> *) b. Monad m => m b -> m b  

which, at this stage of my Haskell progress, is just pure Voodoo. 
Why isn?t it?s signature  asString :: IO String -> String ?


Another naive attempt is 
asString ioStr = str where  
    str <- ioStr

and then compiler says
parse error on input ?<-?


Many Thanks 

Mike



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

Message: 2
Date: Wed, 10 Jun 2015 12:47:54 -0400
From: Steven Williams <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] 'Simple' function
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Here is return's type signature:

return :: Monad m => a -> m a

What you are doing with the do notation can also be expressed as ioStr
>> = (\str -> return str).

do notation and bind both require you to have a value that has the
same monad as before.

Steven Williams
My PGP Key: http://pgp.mit.edu/pks/lookup?op=get&search=0xCACA6C74669A54
FA

On 10/06/15 12:35, Mike Houghton wrote:
> Hi,
> 
> I?ve been tryimg to write a function  with signature
> 
> asString :: IO String -> String
> 
> 
> Does someone please have the patience to explain to me what the
> compiler error messages really mean for these two attempts and
> exactly what I?m doing (!!!) If I *do not* give this function any
> type signature then it works i.e..
> 
> asString ioStr = do str <- ioStr return $ str
> 
> and the compiler tells me its signature is
> 
> asString :: forall (m :: * -> *) b. Monad m => m b -> m b
> 
> which, at this stage of my Haskell progress, is just pure Voodoo. 
> Why isn?t it?s signature  asString :: IO String -> String ?
> 
> 
> Another naive attempt is asString ioStr = str where str <- ioStr
> 
> and then compiler says parse error on input ?<-?
> 
> 
> Many Thanks
> 
> Mike
> 
> _______________________________________________ Beginners mailing
> list [email protected] 
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBAgAGBQJVeGo5AAoJEMrKbHRmmlT6N8UP/i/tAhDtyHiG3sgH3e5xAqyt
JAsyX2JaBQVjERRVaJQy1+Pg9hNdGBCrVljxY0BH5B8np956bnuIEyZKtSc2i2Jc
HM0lBesyzCYqw29QxAyFFno07iXQllocZaHUIgC4AoNYO5zNGSPYcNaB4O5SYoKl
83Cjz97BHgAHkvHpsLDLOpizOkP+CsXwi8s/KRKoidLkbQpmv9SpqiFvmm9u+UK1
emZF/4veFE4Ay3AvIsxMpn7M5hVoKgat1xyGX02IrenvkOL69IIYc+4OvzK49Lxg
e8jrAehJDMh+U7zN+qVCY1ZyJbJF+uGawFC+XoswOdAra+Q23te77RKkligkmN7s
ACut72hwTejZN/sIaORqZXuy+HUY1LjlJnlz0RCdG1CLkr3EaKG5ZCX3E2N8RnxL
1CKtEdtFJGDeBcIBh5my/7IC22loTpVhBhPU2DPo+iOP2sRsUs0nllbqbjGfGpuE
m37dR/tfq9FKwqYS5RUuAcZ8fWuPdojmO2WvI4thHBGJhsRK4gqhAI4MnKLHBEoL
xfyHSaoFif/jC7peF/+ZPjKSsIpCJU+R/tDUBM9u22o3IVeTs1sWGZXM7J32tlGc
K/MTF/F3phcxwSCqb99WBHhXOIkKSgp47gx1INgDZFug/CgjUI1Sl4jvZ5j/45D5
+RlHcYv+qp4J8nI59pFW
=Vunc
-----END PGP SIGNATURE-----


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

Message: 3
Date: Wed, 10 Jun 2015 13:06:07 -0400
From: Brandon Allbery <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] 'Simple' function
Message-ID:
        <cakfcl4xdt10zuxndmbas5c30v6qeenarl5pm4jhkinowajv...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Wed, Jun 10, 2015 at 12:35 PM, Mike Houghton <[email protected]
> wrote:

> asString ioStr = do
>     str <- ioStr
>     return $ str
>
> and the compiler tells me its signature is
>
> asString :: forall (m :: * -> *) b. Monad m => m b -> m b
>
> which, at this stage of my Haskell progress, is just pure Voodoo.
> Why isn?t it?s signature  asString :: IO String -> String ?
>

Because the only thing it knows about ioStr is that it is a monadic action.
IO is not the only monad, nor even the only useful monad. And "do" syntax
including <- is not specific to IO.

That said, most of the type signature it showed you is only important if
you are doing advanced things like type level programming. The short
version of that type signature is

    asString :: Monad m -> m b -> m b

asString ioStr = str where
>     str <- ioStr
>
> and then compiler says
> parse error on input ?<-?
>

<- is part of "do" syntax, it cannot be used by itself like that.

Just to give you some idea of what's really going on, let me show you that
first one without the "do" syntax:

asString ioStr = ioStr >>= (\s -> return $ s)


(Let me additionally note that the "$" does nothing whatsoever in either
case, and can and should be left out. Moreover, (x >>= \y -> return y) is
just a long-winded way of writing (x).)

-- 
brandon s allbery kf8nh                               sine nomine associates
[email protected]                                  [email protected]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150610/f3463781/attachment-0001.html>

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

Message: 4
Date: Wed, 10 Jun 2015 13:08:43 -0400
From: aldiyen <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] 'Simple' function
Message-ID: <[email protected]>
Content-Type: text/plain;       charset=utf-8

And just as a note, you can't really ever get the value inside the IO monad 
out. IO is not pure / non-deterministic, since it depends on something outside 
the program, and there's no way to "make it pure", as it were. You have to do 
all your operations on that String within the context of an IO

-aldiyen



> On Jun 10, 2015, at 12:47, Steven Williams <[email protected]> 
> wrote:
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Here is return's type signature:
> 
> return :: Monad m => a -> m a
> 
> What you are doing with the do notation can also be expressed as ioStr
>>> = (\str -> return str).
> 
> do notation and bind both require you to have a value that has the
> same monad as before.
> 
> Steven Williams
> My PGP Key: http://pgp.mit.edu/pks/lookup?op=get&search=0xCACA6C74669A54
> FA
> 
>> On 10/06/15 12:35, Mike Houghton wrote:
>> Hi,
>> 
>> I?ve been tryimg to write a function  with signature
>> 
>> asString :: IO String -> String
>> 
>> 
>> Does someone please have the patience to explain to me what the
>> compiler error messages really mean for these two attempts and
>> exactly what I?m doing (!!!) If I *do not* give this function any
>> type signature then it works i.e..
>> 
>> asString ioStr = do str <- ioStr return $ str
>> 
>> and the compiler tells me its signature is
>> 
>> asString :: forall (m :: * -> *) b. Monad m => m b -> m b
>> 
>> which, at this stage of my Haskell progress, is just pure Voodoo. 
>> Why isn?t it?s signature  asString :: IO String -> String ?
>> 
>> 
>> Another naive attempt is asString ioStr = str where str <- ioStr
>> 
>> and then compiler says parse error on input ?<-?
>> 
>> 
>> Many Thanks
>> 
>> Mike
>> 
>> _______________________________________________ Beginners mailing
>> list [email protected] 
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2
> 
> iQIcBAEBAgAGBQJVeGo5AAoJEMrKbHRmmlT6N8UP/i/tAhDtyHiG3sgH3e5xAqyt
> JAsyX2JaBQVjERRVaJQy1+Pg9hNdGBCrVljxY0BH5B8np956bnuIEyZKtSc2i2Jc
> HM0lBesyzCYqw29QxAyFFno07iXQllocZaHUIgC4AoNYO5zNGSPYcNaB4O5SYoKl
> 83Cjz97BHgAHkvHpsLDLOpizOkP+CsXwi8s/KRKoidLkbQpmv9SpqiFvmm9u+UK1
> emZF/4veFE4Ay3AvIsxMpn7M5hVoKgat1xyGX02IrenvkOL69IIYc+4OvzK49Lxg
> e8jrAehJDMh+U7zN+qVCY1ZyJbJF+uGawFC+XoswOdAra+Q23te77RKkligkmN7s
> ACut72hwTejZN/sIaORqZXuy+HUY1LjlJnlz0RCdG1CLkr3EaKG5ZCX3E2N8RnxL
> 1CKtEdtFJGDeBcIBh5my/7IC22loTpVhBhPU2DPo+iOP2sRsUs0nllbqbjGfGpuE
> m37dR/tfq9FKwqYS5RUuAcZ8fWuPdojmO2WvI4thHBGJhsRK4gqhAI4MnKLHBEoL
> xfyHSaoFif/jC7peF/+ZPjKSsIpCJU+R/tDUBM9u22o3IVeTs1sWGZXM7J32tlGc
> K/MTF/F3phcxwSCqb99WBHhXOIkKSgp47gx1INgDZFug/CgjUI1Sl4jvZ5j/45D5
> +RlHcYv+qp4J8nI59pFW
> =Vunc
> -----END PGP SIGNATURE-----
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

Message: 5
Date: Wed, 10 Jun 2015 13:16:39 -0400
From: Brandon Allbery <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] 'Simple' function
Message-ID:
        <CAKFCL4Uf+sjZ2y16F2REvxAv3vkE2QnKxhPAf6=qbje0hzu...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Wed, Jun 10, 2015 at 1:06 PM, Brandon Allbery <[email protected]>
wrote:

> asString :: Monad m -> m b -> m b


Typoed, sigh....

  asString :: Monad m => m b -> m b

The thing before the => is a "constraint", in this specifying that the type
"m" must be a type for which an instance of the Monad typeclass has been
defined.

-- 
brandon s allbery kf8nh                               sine nomine associates
[email protected]                                  [email protected]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150610/0eba8c17/attachment-0001.html>

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

Message: 6
Date: Wed, 10 Jun 2015 19:20:10 +0200
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] 'Simple' function
Message-ID:
        <cap1qinapmzzenakexy3ljtkl8c6vks+qfirjnbe81m6ze-u...@mail.gmail.com>
Content-Type: text/plain; charset=UTF-8

Mike, if you are trying to run a "hello world" program in ghci, here
are 2 working functions.

-- #1 : all it does is prompts for input and sends the value back to IO

module Text where

ioStr :: IO()
ioStr = do
  putStrLn "enter anything"
  str <- getLine
  putStrLn str


-- #2 this program prepends the string you pass to it as an arg with "Hello"

str2str:: String -> String
str2str s = "Hello " ++ s


-- how to run:
-- #1 : ioStr
-- #2 : str2str "some text"

hope this helps


On 10 June 2015 at 19:08, aldiyen <[email protected]> wrote:
> And just as a note, you can't really ever get the value inside the IO monad 
> out. IO is not pure / non-deterministic, since it depends on something 
> outside the program, and there's no way to "make it pure", as it were. You 
> have to do all your operations on that String within the context of an IO
>
> -aldiyen
>
>
>
>> On Jun 10, 2015, at 12:47, Steven Williams <[email protected]> 
>> wrote:
>>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Here is return's type signature:
>>
>> return :: Monad m => a -> m a
>>
>> What you are doing with the do notation can also be expressed as ioStr
>>>> = (\str -> return str).
>>
>> do notation and bind both require you to have a value that has the
>> same monad as before.
>>
>> Steven Williams
>> My PGP Key: http://pgp.mit.edu/pks/lookup?op=get&search=0xCACA6C74669A54
>> FA
>>
>>> On 10/06/15 12:35, Mike Houghton wrote:
>>> Hi,
>>>
>>> I?ve been tryimg to write a function  with signature
>>>
>>> asString :: IO String -> String
>>>
>>>
>>> Does someone please have the patience to explain to me what the
>>> compiler error messages really mean for these two attempts and
>>> exactly what I?m doing (!!!) If I *do not* give this function any
>>> type signature then it works i.e..
>>>
>>> asString ioStr = do str <- ioStr return $ str
>>>
>>> and the compiler tells me its signature is
>>>
>>> asString :: forall (m :: * -> *) b. Monad m => m b -> m b
>>>
>>> which, at this stage of my Haskell progress, is just pure Voodoo.
>>> Why isn?t it?s signature  asString :: IO String -> String ?
>>>
>>>
>>> Another naive attempt is asString ioStr = str where str <- ioStr
>>>
>>> and then compiler says parse error on input ?<-?
>>>
>>>
>>> Many Thanks
>>>
>>> Mike
>>>
>>> _______________________________________________ Beginners mailing
>>> list [email protected]
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>> -----BEGIN PGP SIGNATURE-----
>> Version: GnuPG v2
>>
>> iQIcBAEBAgAGBQJVeGo5AAoJEMrKbHRmmlT6N8UP/i/tAhDtyHiG3sgH3e5xAqyt
>> JAsyX2JaBQVjERRVaJQy1+Pg9hNdGBCrVljxY0BH5B8np956bnuIEyZKtSc2i2Jc
>> HM0lBesyzCYqw29QxAyFFno07iXQllocZaHUIgC4AoNYO5zNGSPYcNaB4O5SYoKl
>> 83Cjz97BHgAHkvHpsLDLOpizOkP+CsXwi8s/KRKoidLkbQpmv9SpqiFvmm9u+UK1
>> emZF/4veFE4Ay3AvIsxMpn7M5hVoKgat1xyGX02IrenvkOL69IIYc+4OvzK49Lxg
>> e8jrAehJDMh+U7zN+qVCY1ZyJbJF+uGawFC+XoswOdAra+Q23te77RKkligkmN7s
>> ACut72hwTejZN/sIaORqZXuy+HUY1LjlJnlz0RCdG1CLkr3EaKG5ZCX3E2N8RnxL
>> 1CKtEdtFJGDeBcIBh5my/7IC22loTpVhBhPU2DPo+iOP2sRsUs0nllbqbjGfGpuE
>> m37dR/tfq9FKwqYS5RUuAcZ8fWuPdojmO2WvI4thHBGJhsRK4gqhAI4MnKLHBEoL
>> xfyHSaoFif/jC7peF/+ZPjKSsIpCJU+R/tDUBM9u22o3IVeTs1sWGZXM7J32tlGc
>> K/MTF/F3phcxwSCqb99WBHhXOIkKSgp47gx1INgDZFug/CgjUI1Sl4jvZ5j/45D5
>> +RlHcYv+qp4J8nI59pFW
>> =Vunc
>> -----END PGP SIGNATURE-----
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 84, Issue 17
*****************************************

Reply via email to