From 946a450995d874c807faa16a5df817ca80a7ecb0 Mon Sep 17 00:00:00 2001 From: i Date: Thu, 8 Aug 2013 15:05:01 -0400 Subject: '/' is a character Do you mean no letters? --- 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 be7d8669..9847ef2a 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -131,7 +131,7 @@ add 1 2 -- 3 -- with backticks: 1 `add` 2 -- 3 --- You can also define functions that have no characters! This lets +-- You can also define functions that have no letters! This lets -- you define your own operators! Here's an operator that does -- integer division (//) a b = a `div` b -- cgit v1.2.3 From 76526895ff276939dbd4a8f36f631588459584ba Mon Sep 17 00:00:00 2001 From: Xiao Chuan Yu Date: Mon, 12 Aug 2013 11:17:37 -0400 Subject: Update haskell.html.markdown Just a typo. https://github.com/adambard/learnxinyminutes-docs/issues/190 --- 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 9847ef2a..e3ec3f38 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -84,7 +84,7 @@ not False -- True -- rest of the elements of this "infinite" list don't exist yet! Haskell won't -- actually evaluate them until it needs to. -- joining two lists +-- joining two lists [1..5] ++ [6..10] -- adding to the head of a list -- cgit v1.2.3 From 9e14fd6d364e9e33fcc5ad38c47dafd27e4e37ee Mon Sep 17 00:00:00 2001 From: Scott Feeney Date: Fri, 20 Sep 2013 01:25:36 -0400 Subject: Haskell: fix comment out of sync with code --- 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 e3ec3f38..6b3c6e17 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -329,7 +329,7 @@ main' = interact countLines sayHello :: IO () sayHello = do putStrLn "What is your name?" - name <- getLine -- this gets a line and gives it the name "input" + name <- getLine -- this gets a line and gives it the name "name" putStrLn $ "Hello, " ++ name -- Exercise: write your own version of `interact` that only reads -- cgit v1.2.3 From 001093d53af262cdcae53a09f080a6105151bce0 Mon Sep 17 00:00:00 2001 From: Max Goldstein Date: Wed, 23 Oct 2013 15:19:55 -0400 Subject: Typo You don't need to credit me. --- 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 6b3c6e17..267b40af 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -11,7 +11,7 @@ makes coding a real joy for me. ```haskell -- Single line comments start with two dashes. {- Multiline comments can be enclosed -en a block like this. +in a block like this. -} ---------------------------------------------------- -- cgit v1.2.3 From 29f06c2d2fd8e57a11816969da3d65f68b932a2d Mon Sep 17 00:00:00 2001 From: Simon Shine Date: Mon, 2 Dec 2013 13:09:58 +0100 Subject: [haskell/en-en] Fixed 80-character margin --- haskell.html.markdown | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index 267b40af..341c013e 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -4,9 +4,9 @@ contributors: - ["Adit Bhargava", "http://adit.io"] --- -Haskell was designed as a practical, purely functional programming language. It's famous for -its monads and its type system, but I keep coming back to it because of its elegance. Haskell -makes coding a real joy for me. +Haskell was designed as a practical, purely functional programming +language. It's famous for its monads and its type system, but I keep coming back +to it because of its elegance. Haskell makes coding a real joy for me. ```haskell -- Single line comments start with two dashes. @@ -401,7 +401,9 @@ 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: +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 qsort [] = [] -- cgit v1.2.3 From 718693ef48641e28c3382467ae2959322923fcda Mon Sep 17 00:00:00 2001 From: Aaron Raimist Date: Mon, 3 Feb 2014 17:09:52 -0600 Subject: [haskell/en] Fixes issue #510 --- 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 341c013e..e0489710 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -303,7 +303,7 @@ Nothing -- of type `Maybe a` for any `a` -- While IO can't be explained fully without explaining monads, -- it is not hard to explain enough to get going. --- When a Haskell program is executed, the function `main` is +-- When a Haskell program is executed, `main` is -- called. It must return a value of type `IO ()`. For example: main :: IO () -- cgit v1.2.3 From 6933d24227ec5a0f220bf897e57d5222eaba0084 Mon Sep 17 00:00:00 2001 From: Geoffrey Liu Date: Sun, 12 Oct 2014 12:24:52 -0700 Subject: Capitalize language names. See #137 --- 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 e0489710..ad12de2a 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -1,5 +1,5 @@ --- -language: haskell +language: Haskell contributors: - ["Adit Bhargava", "http://adit.io"] --- -- cgit v1.2.3 From a7b885816d08372d33e0eece7c8e0834c699e7a6 Mon Sep 17 00:00:00 2001 From: hobozo Date: Tue, 21 Oct 2014 15:30:30 -0700 Subject: Update haskell.html.markdown Corrected terminology: currying -> partial application --- haskell.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index ad12de2a..2785405c 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -171,8 +171,8 @@ foldl1 (\acc x -> acc + x) [1..5] -- 15 -- 4. More functions ---------------------------------------------------- --- currying: if you don't pass in all the arguments to a function, --- it gets "curried". That means it returns a function that takes the +-- partial application: if you don't pass in all the arguments to a function, +-- it gets "partially applied". That means it returns a function that takes the -- rest of the arguments. add a b = a + b -- cgit v1.2.3 From 458bbd063ad78c3ba6b0d114226f94edf0dab708 Mon Sep 17 00:00:00 2001 From: Julien Cretel Date: Fri, 21 Nov 2014 17:28:38 +0000 Subject: Fix some inaccuracies in haskell.html.markdown - The bottom of the "List and Tuples" section may mislead the reader into thinking that the `fst` and `snd` functions can be applied to any tuple; it's worth mentioning that those functions only apply to pairs. - The example demonstrating the use of the function-application operator (`$`) in combination with the function-composition operator (`.`) seems a bit contrived. For completeness, I've added an example that uses `$` alone. - "If statements" and "case statements" are actually expressions, in Haskell; I've replaced all occurences of the word "statement" appearing in that context by the word "expression". - Minor wording improvement (replaced "because" by a semicolon). --- haskell.html.markdown | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index 2785405c..748a29da 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -110,7 +110,7 @@ last [1..5] -- 5 -- A tuple: ("haskell", 1) --- accessing elements of a tuple +-- accessing elements of a pair (i.e. a tuple of length 2) fst ("haskell", 1) -- "haskell" snd ("haskell", 1) -- 1 @@ -195,8 +195,8 @@ foo 5 -- 75 -- fixing precedence -- Haskell has another function called `$`. This changes the precedence -- so that everything to the left of it gets computed first and then applied --- to everything on the right. You can use `.` and `$` to get rid of a lot --- of parentheses: +-- to everything on the right. You can use `$` (often in combination with `.`) +-- to get rid of a lot of parentheses: -- before (even (fib 7)) -- true @@ -204,6 +204,9 @@ foo 5 -- 75 -- after even . fib $ 7 -- true +-- equivalently +even $ fib 7 -- true + ---------------------------------------------------- -- 5. Type signatures ---------------------------------------------------- @@ -227,24 +230,24 @@ double :: Integer -> Integer double x = x * 2 ---------------------------------------------------- --- 6. Control Flow and If Statements +-- 6. Control Flow and If Expressions ---------------------------------------------------- --- if statements +-- if expressions haskell = if 1 == 1 then "awesome" else "awful" -- haskell = "awesome" --- if statements can be on multiple lines too, indentation is important +-- if expressions can be on multiple lines too, indentation is important haskell = if 1 == 1 then "awesome" else "awful" --- case statements: Here's how you could parse command line arguments +-- case expressions: Here's how you could parse command line arguments case args of "help" -> printHelp "start" -> startProgram _ -> putStrLn "bad args" --- Haskell doesn't have loops because it uses recursion instead. +-- Haskell doesn't have loops; it uses recursion instead. -- map applies a function over every element in an array map (*2) [1..5] -- [2, 4, 6, 8, 10] -- cgit v1.2.3 From 5f45319d577e1ef8a0d28f08fd37a7ed76433958 Mon Sep 17 00:00:00 2001 From: Devin McGinty Date: Sat, 31 Jan 2015 19:40:55 -0500 Subject: Add more information on ranges in Haskell --- haskell.html.markdown | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index 748a29da..d5dd5141 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -67,10 +67,18 @@ not False -- True ---------------------------------------------------- -- Every element in a list must have the same type. --- Two lists that are the same +-- These two lists are the same [1, 2, 3, 4, 5] [1..5] +-- Ranges are versatile. +['A'..'F'] -- "ABCDEF" + +-- You can create a step in a range. +[0,2..10] -- [0, 2, 4, 6, 8, 10] +[5..1] -- This doesn't work because Haskell defaults to incrementing. +[5,4..1] -- [5, 4, 3, 2, 1] + -- You can also have infinite lists in Haskell! [1..] -- a list of all the natural numbers -- cgit v1.2.3 From 411b2b01d3a83369f0754ec03b40499e4f8bcade Mon Sep 17 00:00:00 2001 From: Devin McGinty Date: Sun, 1 Feb 2015 16:39:52 -0500 Subject: Add example of string-as-list and fix punctuation --- haskell.html.markdown | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index d5dd5141..52433aaa 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -59,6 +59,7 @@ not False -- True "Hello " ++ "world!" -- "Hello world!" -- A string is a list of characters +['H', 'e', 'l', 'l', 'o'] -- "Hello" "This is a string" !! 0 -- 'T' @@ -67,7 +68,7 @@ not False -- True ---------------------------------------------------- -- Every element in a list must have the same type. --- These two lists are the same +-- These two lists are the same: [1, 2, 3, 4, 5] [1..5] -- cgit v1.2.3 From 36a296de5d8d82212755ba33388517486f7f804c Mon Sep 17 00:00:00 2001 From: Zach Munro-Cape Date: Sun, 1 Mar 2015 15:16:29 -0400 Subject: Moved explanation of indexing into a list earlier This way, it is clear what [1..] !! 999 means later on. --- haskell.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index 52433aaa..79fbf09f 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -80,6 +80,9 @@ not False -- True [5..1] -- This doesn't work because Haskell defaults to incrementing. [5,4..1] -- [5, 4, 3, 2, 1] +-- indexing into a list +[0..] !! 5 -- 5 + -- You can also have infinite lists in Haskell! [1..] -- a list of all the natural numbers @@ -99,9 +102,6 @@ not False -- True -- adding to the head of a list 0:[1..5] -- [0, 1, 2, 3, 4, 5] --- indexing into a list -[0..] !! 5 -- 5 - -- more list operations head [1..5] -- 1 tail [1..5] -- [2, 3, 4, 5] -- cgit v1.2.3 From 4e00fa4734bd39436f3336b4ce1034b65c265657 Mon Sep 17 00:00:00 2001 From: Cornel Punga Date: Mon, 16 Mar 2015 21:09:17 +0200 Subject: Update haskell.html.markdown. Wrong explanation about '$' operator --- haskell.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index 79fbf09f..d5dfd122 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -202,9 +202,9 @@ foo = (*5) . (+10) foo 5 -- 75 -- fixing precedence --- Haskell has another function called `$`. This changes the precedence --- so that everything to the left of it gets computed first and then applied --- to everything on the right. You can use `$` (often in combination with `.`) +-- Haskell has another function called `$`. Anything appearing after it will +-- take precedence over anything that comes before. +-- You can use `$` (often in combination with `.`) -- to get rid of a lot of parentheses: -- before -- cgit v1.2.3 From 9fb21f1ce4c02e8cad50046f90d026ccab284626 Mon Sep 17 00:00:00 2001 From: Cornel Punga Date: Mon, 16 Mar 2015 21:24:21 +0200 Subject: Haskell.html.markdown. Wrong result of an expression. The seventh Fibonacci number is 13 (odd number), so the result of 'even 13' is false. --- haskell.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index d5dfd122..f1025d44 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -208,13 +208,13 @@ foo 5 -- 75 -- to get rid of a lot of parentheses: -- before -(even (fib 7)) -- true +(even (fib 7)) -- false -- after -even . fib $ 7 -- true +even . fib $ 7 -- false -- equivalently -even $ fib 7 -- true +even $ fib 7 -- false ---------------------------------------------------- -- 5. Type signatures -- cgit v1.2.3 From a81affb3027b81aa16eba8cac159a18081cff449 Mon Sep 17 00:00:00 2001 From: Geoff Liu Date: Mon, 16 Mar 2015 14:07:19 -0600 Subject: Make the two fib functions consistent --- haskell.html.markdown | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index 79fbf09f..2f807c5f 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -148,12 +148,12 @@ add 1 2 -- 3 -- Guards: an easy way to do branching in functions fib x - | x < 2 = x + | x < 2 = 1 | otherwise = fib (x - 1) + fib (x - 2) -- Pattern matching is similar. Here we have given three different -- definitions for fib. Haskell will automatically call the first --- function that matches the pattern of the value. +-- function that matches the pattern of the value. fib 1 = 1 fib 2 = 2 fib x = fib (x - 1) + fib (x - 2) @@ -181,7 +181,7 @@ foldl1 (\acc x -> acc + x) [1..5] -- 15 ---------------------------------------------------- -- partial application: if you don't pass in all the arguments to a function, --- it gets "partially applied". That means it returns a function that takes the +-- it gets "partially applied". That means it returns a function that takes the -- rest of the arguments. add a b = a + b @@ -319,13 +319,13 @@ Nothing -- of type `Maybe a` for any `a` -- called. It must return a value of type `IO ()`. For example: main :: IO () -main = putStrLn $ "Hello, sky! " ++ (say Blue) +main = putStrLn $ "Hello, sky! " ++ (say Blue) -- putStrLn has type String -> IO () --- It is easiest to do IO if you can implement your program as --- a function from String to String. The function +-- It is easiest to do IO if you can implement your program as +-- a function from String to String. The function -- interact :: (String -> String) -> IO () --- inputs some text, runs a function on it, and prints out the +-- inputs some text, runs a function on it, and prints out the -- output. countLines :: String -> String @@ -339,43 +339,43 @@ main' = interact countLines -- the `do` notation to chain actions together. For example: sayHello :: IO () -sayHello = do +sayHello = do putStrLn "What is your name?" name <- getLine -- this gets a line and gives it the name "name" putStrLn $ "Hello, " ++ name - + -- Exercise: write your own version of `interact` that only reads -- one line of input. - + -- The code in `sayHello` will never be executed, however. The only --- action that ever gets executed is the value of `main`. --- To run `sayHello` comment out the above definition of `main` +-- action that ever gets executed is the value of `main`. +-- To run `sayHello` comment out the above definition of `main` -- and replace it with: -- main = sayHello --- Let's understand better how the function `getLine` we just +-- Let's understand better how the function `getLine` we just -- used works. Its type is: -- getLine :: IO String -- You can think of a value of type `IO a` as representing a --- computer program that will generate a value of type `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 +-- store and reuse this value using `<-`. We can also -- make our own action of type `IO String`: action :: IO String action = do putStrLn "This is a line. Duh" - input1 <- getLine + input1 <- getLine input2 <- getLine -- The type of the `do` statement is that of its last line. - -- `return` is not a keyword, but merely a function + -- `return` is not a keyword, but merely a function return (input1 ++ "\n" ++ input2) -- return :: String -> IO String -- We can use this just like we used `getLine`: main'' = do putStrLn "I will echo two lines!" - result <- action + result <- action putStrLn result putStrLn "This was all, folks!" -- cgit v1.2.3 From 2f43da109ffab5a4d3dd582cc51a7c3d95dd4987 Mon Sep 17 00:00:00 2001 From: Cornel Punga Date: Wed, 25 Mar 2015 18:08:32 +0200 Subject: [haskell.html.markdown] Changed explanation for Haskell '$' operator --- haskell.html.markdown | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index f1025d44..6bdc78e0 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -202,10 +202,12 @@ foo = (*5) . (+10) foo 5 -- 75 -- fixing precedence --- Haskell has another function called `$`. Anything appearing after it will --- take precedence over anything that comes before. --- You can use `$` (often in combination with `.`) --- to get rid of a lot of parentheses: +-- Haskell has another operator called `$`. This operator applies a function +-- to a given parameter. In contrast to standard function application, which +-- has highest possible priority of 10 and is left-associative, the `$` operator +-- has priority of 0 and is right-associative. Such a low priority means that +-- all other operators on both sides of `$` will be evaluated before applying +-- the `$`. -- before (even (fib 7)) -- false -- cgit v1.2.3 From e8a1ee8912d1c9bb0145c2afbdc530463fc612b7 Mon Sep 17 00:00:00 2001 From: Cornel Punga Date: Fri, 27 Mar 2015 15:25:33 +0200 Subject: [haskell.html.markdown] Explanation for Haskell '$' operator with support from @geoffliu --- haskell.html.markdown | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index 6bdc78e0..6c98c2b6 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -205,9 +205,8 @@ foo 5 -- 75 -- Haskell has another operator called `$`. This operator applies a function -- to a given parameter. In contrast to standard function application, which -- has highest possible priority of 10 and is left-associative, the `$` operator --- has priority of 0 and is right-associative. Such a low priority means that --- all other operators on both sides of `$` will be evaluated before applying --- the `$`. +-- has priority of 0 and is right-associative. Such a low priority means that +-- the expression on its right is applied as the parameter to the function on its left. -- before (even (fib 7)) -- false -- cgit v1.2.3 From 745ce28d7e72a1de6a1a386f91f8fcae0c99b324 Mon Sep 17 00:00:00 2001 From: Tiddo Langerak Date: Mon, 27 Apr 2015 10:16:16 +0200 Subject: Fixed haskell foldr example For #1068 --- 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 f28fcfe7..6a64442f 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -282,7 +282,7 @@ foldl (\x y -> 2*x + y) 4 [1,2,3] -- 43 foldr (\x y -> 2*x + y) 4 [1,2,3] -- 16 -- This is now the same as -(2 * 3 + (2 * 2 + (2 * 1 + 4))) +(2 * 1 + (2 * 2 + (2 * 3 + 4))) ---------------------------------------------------- -- 7. Data Types -- cgit v1.2.3 From 8544847845c0405e54acadf5125edc0554d73b75 Mon Sep 17 00:00:00 2001 From: ven Date: Mon, 6 Jul 2015 10:40:05 +0200 Subject: change haskell's operator `$` description wording for #1161 --- haskell.html.markdown | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index 6a64442f..369b1b20 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -209,14 +209,15 @@ foo 5 -- 75 -- the expression on its right is applied as the parameter to the function on its left. -- before -(even (fib 7)) -- false - --- after -even . fib $ 7 -- false +even (fib 7) -- false -- equivalently even $ fib 7 -- false +-- composing functions +even . fib $ 7 -- false + + ---------------------------------------------------- -- 5. Type signatures ---------------------------------------------------- -- cgit v1.2.3