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:  (.) vs ($) (Sumit Sahrawat, Maths & Computing, IIT (BHU))
   2. Re:  Haskell Platform SHA (Frerich Raabe)


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

Message: 1
Date: Sat, 4 Apr 2015 11:16:59 +0530
From: "Sumit Sahrawat, Maths & Computing, IIT (BHU)"
        <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] (.) vs ($)
Message-ID:
        <cajbew8ngu_1viuhmyd5ysyv-fjvukv0jf0e_3aahswrcvtq...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

To reiterate what others have said,

   readFile . head xs
== readFile . (head xs)     { function application binds strongest }
== (.) readFile (head xs)   { operators are also functions }

The types,

   (.)      :: (b -> c) -> (a -> b) -> (a -> c)
   readFile :: FilePath -> IO String
   head xs  :: FilePath

This cannot work as the types don't match. On the other hand, using ($)
instead of (.) will work.
Try writing that out and reasoning with the types on pen and paper, as an
exercise.

If you're interested, there is an excellent post about equational reasoning
here: http://www.haskellforall.com/2013/12/equational-reasoning.html

Enjoy :)

On 4 April 2015 at 08:10, Mike Meyer <[email protected]> wrote:

> As is often the case with Haskell, your answer is in the types:
>
> Prelude> :t ($)
> ($) :: (a -> b) -> a -> b
> Prelude> :t (.)
> (.) :: (b -> c) -> (a -> b) -> a -> c
>
> So $ takes a function and applies it to a value. . takes two functions and
> composes them and applies the result to a value.
>
> So readFirst xs = (readFile.head) xs, or just readFirst = readFile .
> head. But readFirst xs = (readFile $ head) xs will also fail, because
> readFile doesn't work on objects of type head.
>
> On Fri, Apr 3, 2015 at 9:23 PM, Vale Cofer-Shabica <
> [email protected]> wrote:
>
>> Could someone please explain why the commented line fails
>> spectacularly while the final line succeeds?
>>
>> >import System.IO (getContents)
>> >import System.Environment (getArgs)
>>
>> >fileInput :: IO String
>> >fileInput = getArgs>>=readFirst where
>> >  readFirst :: [FilePath] -> IO String
>> >  readFirst [] = System.IO.getContents
>> >--readFirst xs = readFile.head xs
>> >  readFirst xs = readFile $ head xs
>>
>>
>> I'm particularly confused given the following typings (from ghci):
>>
>> readFile.head :: [FilePath] -> IO String
>> readFile.head [] :: a -> IO String
>>
>> And this is still stranger:
>>
>> :type readFile.head ["foo", "bar"]
>>
>> <interactive>:28:16:
>>     Couldn't match expected type `a0 -> FilePath'
>>                 with actual type `[Char]'
>>     In the expression: "foo"
>>     In the first argument of `head', namely `["foo", "bar"]'
>>     In the second argument of `(.)', namely `head ["foo", "bar"]'
>>
>> <interactive>:28:23:
>>     Couldn't match expected type `a0 -> FilePath'
>>                 with actual type `[Char]'
>>     In the expression: "bar"
>>     In the first argument of `head', namely `["foo", "bar"]'
>>     In the second argument of `(.)', namely `head ["foo", "bar"]'
>>
>>
>> Many thanks in advance,
>> vale
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
>
> On Fri, Apr 3, 2015 at 9:23 PM, Vale Cofer-Shabica <
> [email protected]> wrote:
>
>> Could someone please explain why the commented line fails
>> spectacularly while the final line succeeds?
>>
>> >import System.IO (getContents)
>> >import System.Environment (getArgs)
>>
>> >fileInput :: IO String
>> >fileInput = getArgs>>=readFirst where
>> >  readFirst :: [FilePath] -> IO String
>> >  readFirst [] = System.IO.getContents
>> >--readFirst xs = readFile.head xs
>> >  readFirst xs = readFile $ head xs
>>
>>
>> I'm particularly confused given the following typings (from ghci):
>>
>> readFile.head :: [FilePath] -> IO String
>> readFile.head [] :: a -> IO String
>>
>> And this is still stranger:
>>
>> :type readFile.head ["foo", "bar"]
>>
>> <interactive>:28:16:
>>     Couldn't match expected type `a0 -> FilePath'
>>                 with actual type `[Char]'
>>     In the expression: "foo"
>>     In the first argument of `head', namely `["foo", "bar"]'
>>     In the second argument of `(.)', namely `head ["foo", "bar"]'
>>
>> <interactive>:28:23:
>>     Couldn't match expected type `a0 -> FilePath'
>>                 with actual type `[Char]'
>>     In the expression: "bar"
>>     In the first argument of `head', namely `["foo", "bar"]'
>>     In the second argument of `(.)', namely `head ["foo", "bar"]'
>>
>>
>> Many thanks in advance,
>> vale
>> _______________________________________________
>> 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
>
>


-- 
Regards

Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150404/b79ef363/attachment-0001.html>

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

Message: 2
Date: Sat, 04 Apr 2015 10:12:44 +0200
From: Frerich Raabe <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Haskell Platform SHA
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed

On 2015-04-03 22:13, sojourner wrote:
> Downloaded Haskell Platform 2014.2.0.0.0 for Mac OSX from 
> https://www.haskell.org/platform/mac.html [1]. Twice. The SHA-256 on the web 
> page is
> 62f39246ad95dd2aed6ece5138f6297f945d2b450f215d074820294310e0c48a. But 
> running shasum or openssl on the downloaded file results in
> 7c00f945fa7afb0f264bf253759f3dd02944a0ffef7b5f13317fa835ce841952.

I couldn't reproduce this; make sure not to run 'shasum' directly (since 
that'll default to SHA-1). Invoke it like 'shasum -a 256 <file>'. For me, 
that gives:

   $ shasum -a 256  ~/Downloads/Haskell\ Platform\ 2014.2.0.0\ 
64bit.signed.pkg
   62f39246ad95dd2aed6ece5138f6297f945d2b450f215d074820294310e0c48a  
/Users/frerich/Downloads/Haskell Platform 2014.2.0.0 64bit.signed.pkg

-- 
Frerich Raabe - [email protected]
www.froglogic.com - Multi-Platform GUI Testing


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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 82, Issue 5
****************************************

Reply via email to