From a76be91a2d45c7c4a834c2ad6d5164ac907c1038 Mon Sep 17 00:00:00 2001 From: Greg Yang Date: Tue, 20 Oct 2015 12:05:16 -0700 Subject: modify function composition example --- haskell.html.markdown | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index 369b1b20..c6d97496 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -195,11 +195,11 @@ foo 5 -- 15 -- function composition -- the (.) function chains functions together. -- For example, here foo is a function that takes a value. It adds 10 to it, --- multiplies the result of that by 5, and then returns the final value. -foo = (*5) . (+10) +-- multiplies the result of that by 4, and then returns the final value. +foo = (*4) . (+10) --- (5 + 10) * 5 = 75 -foo 5 -- 75 +-- (5 + 10) * 4 = 75 +foo 5 -- 60 -- fixing precedence -- Haskell has another operator called `$`. This operator applies a function -- cgit v1.2.3 From 18edced524b790fe3e6c9bb5f69507ca1bfb0553 Mon Sep 17 00:00:00 2001 From: Greg Yang Date: Tue, 20 Oct 2015 12:10:01 -0700 Subject: update the comment in as well --- haskell.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index c6d97496..e3b29937 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -198,7 +198,7 @@ foo 5 -- 15 -- multiplies the result of that by 4, and then returns the final value. foo = (*4) . (+10) --- (5 + 10) * 4 = 75 +-- (5 + 10) * 4 = 40 foo 5 -- 60 -- fixing precedence -- cgit v1.2.3 From f0bbebe789e310ecd76fcfdfa334291928591fb7 Mon Sep 17 00:00:00 2001 From: Greg Yang Date: Tue, 20 Oct 2015 12:10:50 -0700 Subject: really update the comment --- haskell.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index e3b29937..08611e63 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -198,7 +198,7 @@ foo 5 -- 15 -- multiplies the result of that by 4, and then returns the final value. foo = (*4) . (+10) --- (5 + 10) * 4 = 40 +-- (5 + 10) * 4 = 60 foo 5 -- 60 -- fixing precedence -- cgit v1.2.3 From f6b8b079b49a1fcfdc6143fc51bc5d3738ade8f0 Mon Sep 17 00:00:00 2001 From: Patrik Jansson Date: Fri, 23 Oct 2015 23:31:10 +0200 Subject: Some minor fixes I just noted that the example claiming that (add 10) is the same as (+10) was wrong. (A detail - it should be (10+) to match the argument order.) Then I just continued down making a few similar fixes and terminology updates. /Patrik PS. I've been teaching [Advanced Functional Programming](http://www.cse.chalmers.se/edu/course/afp/) (in Haskell) for a few years at Chalmers. --- haskell.html.markdown | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index 08611e63..2f58b357 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -189,16 +189,16 @@ foo = add 10 -- foo is now a function that takes a number and adds 10 to it foo 5 -- 15 -- Another way to write the same thing -foo = (+10) +foo = (10+) foo 5 -- 15 -- function composition -- the (.) function chains functions together. -- For example, here foo is a function that takes a value. It adds 10 to it, -- multiplies the result of that by 4, and then returns the final value. -foo = (*4) . (+10) +foo = (4*) . (10+) --- (5 + 10) * 4 = 60 +-- 4*(10 + 5) = 60 foo 5 -- 60 -- fixing precedence @@ -222,7 +222,7 @@ even . fib $ 7 -- false -- 5. Type signatures ---------------------------------------------------- --- Haskell has a very strong type system, and everything has a type signature. +-- Haskell has a very strong type system, and every valid expression has a type. -- Some basic types: 5 :: Integer @@ -259,7 +259,7 @@ case args of _ -> putStrLn "bad args" -- Haskell doesn't have loops; it uses recursion instead. --- map applies a function over every element in an array +-- map applies a function over every element in a list map (*2) [1..5] -- [2, 4, 6, 8, 10] @@ -279,7 +279,7 @@ foldl (\x y -> 2*x + y) 4 [1,2,3] -- 43 -- This is the same as (2 * (2 * (2 * 4 + 1) + 2) + 3) --- foldl is left-handed, foldr is right- +-- foldl is left-handed, foldr is right-handed foldr (\x y -> 2*x + y) 4 [1,2,3] -- 16 -- This is now the same as @@ -318,7 +318,7 @@ Nothing -- of type `Maybe a` for any `a` -- it is not hard to explain enough to get going. -- When a Haskell program is executed, `main` is --- called. It must return a value of type `IO ()`. For example: +-- called. It must return a value of type `IO a` for some type `a`. For example: main :: IO () main = putStrLn $ "Hello, sky! " ++ (say Blue) @@ -361,7 +361,7 @@ sayHello = do -- You can think of a value of type `IO a` as representing a -- computer program that will generate a value of type `a` -- when executed (in addition to anything else it does). We can --- store and reuse this value using `<-`. We can also +-- name and reuse this value using `<-`. We can also -- make our own action of type `IO String`: action :: IO String @@ -417,7 +417,7 @@ Hello, Friend! There's a lot more to Haskell, including typeclasses and monads. These are the big ideas that make Haskell such fun to code in. I'll leave you with one final -Haskell example: an implementation of quicksort in Haskell: +Haskell example: an implementation of a quicksort variant in Haskell: ```haskell qsort [] = [] -- cgit v1.2.3 From b5cb14703ac99e70ecd6c1ec2abd9a2b5dbde54d Mon Sep 17 00:00:00 2001 From: Niko Weh Date: Sat, 31 Oct 2015 19:44:04 +1000 Subject: Haskell: Fix !! operator - Use a finite list, as infinite lists are not introduced yet - Use a list starting from 1 instead of 0, to make it obvious that the element returned comes from the list (and is not the second argument to !!). --- haskell.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index 08611e63..936744a0 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -81,7 +81,7 @@ not False -- True [5,4..1] -- [5, 4, 3, 2, 1] -- indexing into a list -[0..] !! 5 -- 5 +[1..10] !! 3 -- 4 -- You can also have infinite lists in Haskell! [1..] -- a list of all the natural numbers -- cgit v1.2.3 From 608615360c7f49cb33c9e7eb3957e031b9b8a89c Mon Sep 17 00:00:00 2001 From: Niko Weh Date: Sat, 31 Oct 2015 22:37:13 +1000 Subject: [haskell/en] Extended section on GHCi - Added the :i command, as i feel that it is as useful as :t. - Added another example for :t, hopefully showcasing it's flexibility - For consistency, changed the name of (.) from function to operator (as is already the case with ($)), and added a short remark in the GHCi section that (most) operators are also functions. --- haskell.html.markdown | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index 936744a0..940cf4c7 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -193,7 +193,7 @@ foo = (+10) foo 5 -- 15 -- function composition --- the (.) function chains functions together. +-- the operator `.` chains functions together. -- For example, here foo is a function that takes a value. It adds 10 to it, -- multiplies the result of that by 4, and then returns the final value. foo = (*4) . (+10) @@ -401,11 +401,26 @@ main'' = do let foo = 5 --- You can see the type of any value with `:t`: +-- You can see the type of any value or expression with `:t`: ->:t foo +> :t foo foo :: Integer +-- Operators, such as `+`, `:` and `$`, are functions. +-- Their type can be inspected by putting the operator in parentheses: + +> :t (:) +(:) :: a -> [a] -> [a] + +-- You can get additional information on any `name` using `:i`: + +> :i (+) +class Num a where + (+) :: a -> a -> a + ... + -- Defined in ‘GHC.Num’ +infixl 6 + + -- You can also run any action of type `IO ()` > sayHello -- cgit v1.2.3 From 410cc03b09870be6da4931725120b44f93b3bcfc Mon Sep 17 00:00:00 2001 From: Robb Shecter Date: Thu, 3 Dec 2015 14:27:24 -0800 Subject: Updating dev environment installation info --- haskell.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index 936744a0..34eee748 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -426,7 +426,7 @@ qsort (p:xs) = qsort lesser ++ [p] ++ qsort greater greater = filter (>= p) xs ``` -Haskell is easy to install. Get it [here](http://www.haskell.org/platform/). +There are two popular ways to install Haskell: The traditional [Cabal-based installation](http://www.haskell.org/platform/), and the newer [Stack-based process](https://www.stackage.org/install). You can find a much gentler introduction from the excellent [Learn you a Haskell](http://learnyouahaskell.com/) or -- cgit v1.2.3