From d064763e9599f3ef4b7bccc1ed7d9df3687367ac Mon Sep 17 00:00:00 2001 From: Patrik Jansson Date: Thu, 9 Feb 2017 16:26:11 +0100 Subject: [haskell/en] some minor fixes (#2550) * [haskell/en] some minor fixes * Minor fixes after comments from @vendethiel --- haskell.html.markdown | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index 4ce1a839..2b6aa2f7 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -68,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 equal: [1, 2, 3, 4, 5] [1..5] @@ -77,11 +77,11 @@ not False -- True -- 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..1] -- [] (Haskell defaults to incrementing) [5,4..1] -- [5, 4, 3, 2, 1] -- indexing into a list -[1..10] !! 3 -- 4 +[1..10] !! 3 -- 4 (zero-based indexing) -- You can also have infinite lists in Haskell! [1..] -- a list of all the natural numbers @@ -152,8 +152,8 @@ fib x | 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. +-- equations for fib. Haskell will automatically use the first +-- equation whose left hand side pattern matches the value. fib 1 = 1 fib 2 = 2 fib x = fib (x - 1) + fib (x - 2) @@ -198,11 +198,11 @@ foo 5 -- 15 -- multiplies the result of that by 4, and then returns the final value. foo = (4*) . (10+) --- 4*(10 + 5) = 60 +-- 4*(10+ 5) = 60 foo 5 -- 60 -- fixing precedence --- Haskell has another operator called `$`. This operator applies a function +-- Haskell has an 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 @@ -244,10 +244,10 @@ double x = x * 2 -- 6. Control Flow and If Expressions ---------------------------------------------------- --- if expressions +-- if-expressions haskell = if 1 == 1 then "awesome" else "awful" -- haskell = "awesome" --- if expressions 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" @@ -295,11 +295,10 @@ data Color = Red | Blue | Green -- Now you can use it in a function: - say :: Color -> String -say Red = "You are Red!" -say Blue = "You are Blue!" -say Green = "You are Green!" +say Red = "You are Red!" +say Blue = "You are Blue!" +say Green = "You are Green!" -- Your data types can have parameters too: @@ -384,8 +383,8 @@ main'' = do -- The type `IO` is an example of a "monad". The way Haskell uses a monad to -- do IO allows it to be a purely functional language. Any function that -- interacts with the outside world (i.e. does IO) gets marked as `IO` in its --- type signature. This lets us reason about what functions are "pure" (don't --- interact with the outside world or modify state) and what functions aren't. +-- type signature. This lets us reason about which functions are "pure" (don't +-- interact with the outside world or modify state) and which functions aren't. -- This is a powerful feature, because it's easy to run pure functions -- concurrently; so, concurrency in Haskell is very easy. -- cgit v1.2.3 From 0a0080a955c11c9b29757d20c74412e6ced67f16 Mon Sep 17 00:00:00 2001 From: ven Date: Thu, 9 Feb 2017 16:27:29 +0100 Subject: #2550 --- 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 2b6aa2f7..ce804415 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -152,7 +152,7 @@ fib x | otherwise = fib (x - 1) + fib (x - 2) -- Pattern matching is similar. Here we have given three different --- equations for fib. Haskell will automatically use the first +-- equations that define fib. Haskell will automatically use the first -- equation whose left hand side pattern matches the value. fib 1 = 1 fib 2 = 2 @@ -198,7 +198,7 @@ foo 5 -- 15 -- multiplies the result of that by 4, and then returns the final value. foo = (4*) . (10+) --- 4*(10+ 5) = 60 +-- 4*(10+5) = 60 foo 5 -- 60 -- fixing precedence -- cgit v1.2.3 From 63a6eb1182205389388e13b680962199ac9b3ffb Mon Sep 17 00:00:00 2001 From: Andy Date: Sat, 1 Apr 2017 22:19:58 +0200 Subject: [haskell] Updating second headline (#2695) * Haskell: Updating second headline * Haskell: Updating second headline (es) * Haskell: Updating second headline (fr) * Haskell: Updating second headline (pl) * Haskell: Updating second headline (pt) * Haskell: Updating second headline (ro) * Haskell: Updating second headline (ru) * Haskell: Updating second headline (cn) --- 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 ce804415..4e254070 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -64,7 +64,7 @@ not False -- True ---------------------------------------------------- --- Lists and Tuples +-- 2. Lists and Tuples ---------------------------------------------------- -- Every element in a list must have the same type. -- cgit v1.2.3 From 21b76a0179735a88a49324ae6ca1f719f0b5ee94 Mon Sep 17 00:00:00 2001 From: Pratik Karki Date: Fri, 25 Aug 2017 13:46:38 +0545 Subject: Add filename(#2832) --- haskell.html.markdown | 1 + 1 file changed, 1 insertion(+) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index 4e254070..70ef8fb2 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -1,5 +1,6 @@ --- language: Haskell +filename: learnhaskell.hs contributors: - ["Adit Bhargava", "http://adit.io"] --- -- cgit v1.2.3 From 177db388313bfc4aa538ee4bfa54d5b72a09537a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=20Polykanine=20A=2EK=2EA=2E=20Menelion=20Elens=C3=BA?= =?UTF-8?q?l=C3=AB?= Date: Sun, 10 Sep 2017 22:26:33 +0300 Subject: [haskell/en] Added Happy Learn Haskell Tutorial. Fixed #2177 --- 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 70ef8fb2..266cf11b 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -444,5 +444,6 @@ qsort (p:xs) = qsort lesser ++ [p] ++ qsort greater 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 +[Learn you a Haskell](http://learnyouahaskell.com/), +[Happy Learn Haskell Tutorial](http://www.happylearnhaskelltutorial.com/) or [Real World Haskell](http://book.realworldhaskell.org/). -- cgit v1.2.3 From 8c30522d58e6c006274952a75c5acd4d104c8828 Mon Sep 17 00:00:00 2001 From: Alex Grejuc Date: Tue, 10 Jul 2018 15:12:23 -0700 Subject: added info about tuples, integrated wild card use into a function definition --- haskell.html.markdown | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index 266cf11b..cad036f1 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -124,6 +124,9 @@ last [1..5] -- 5 fst ("haskell", 1) -- "haskell" snd ("haskell", 1) -- 1 +-- pair element accessing does not work on n-tuples (i.e. triple, quadruple, etc) +snd ("snd", "can't touch this", "da na na na") -- error! see function below to get around this + ---------------------------------------------------- -- 3. Functions ---------------------------------------------------- @@ -159,8 +162,8 @@ fib 1 = 1 fib 2 = 2 fib x = fib (x - 1) + fib (x - 2) --- Pattern matching on tuples: -foo (x, y) = (x + 1, y + 2) +-- Pattern matching on tuples, using wild card (_) to bypass naming an unused value +sndOfTriple (_, y, _) = y -- Pattern matching on lists. Here `x` is the first element -- in the list, and `xs` is the rest of the list. We can write @@ -203,9 +206,9 @@ foo = (4*) . (10+) foo 5 -- 60 -- fixing precedence --- Haskell has an 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 +-- Haskell has an 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 -- the expression on its right is applied as the parameter to the function on its left. @@ -223,7 +226,7 @@ even . fib $ 7 -- false -- 5. Type signatures ---------------------------------------------------- --- Haskell has a very strong type system, and every valid expression has a type. +-- Haskell has a very strong type system, and every valid expression has a type. -- Some basic types: 5 :: Integer -- cgit v1.2.3 From 093e6b62a1aae230f965ad8d1ee2ff8a6b128055 Mon Sep 17 00:00:00 2001 From: Alex Grejuc Date: Tue, 10 Jul 2018 15:15:26 -0700 Subject: moved comment on sndOfTriple --- 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 cad036f1..6a48b60c 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -162,8 +162,8 @@ fib 1 = 1 fib 2 = 2 fib x = fib (x - 1) + fib (x - 2) --- Pattern matching on tuples, using wild card (_) to bypass naming an unused value -sndOfTriple (_, y, _) = y +-- Pattern matching on tuples +sndOfTriple (_, y, _) = y -- you can use a wild card (_) to bypass naming an unused value -- Pattern matching on lists. Here `x` is the first element -- in the list, and `xs` is the rest of the list. We can write -- cgit v1.2.3 From c421b1bd0d18ab57c88665bd14b289e75724cf37 Mon Sep 17 00:00:00 2001 From: Alex Grejuc Date: Tue, 10 Jul 2018 15:34:42 -0700 Subject: trimmed loc over 80 chars --- 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 6a48b60c..e9ddf54d 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -125,7 +125,7 @@ fst ("haskell", 1) -- "haskell" snd ("haskell", 1) -- 1 -- pair element accessing does not work on n-tuples (i.e. triple, quadruple, etc) -snd ("snd", "can't touch this", "da na na na") -- error! see function below to get around this +snd ("snd", "can't touch this", "da na na na") -- error! see function below ---------------------------------------------------- -- 3. Functions @@ -163,7 +163,7 @@ fib 2 = 2 fib x = fib (x - 1) + fib (x - 2) -- Pattern matching on tuples -sndOfTriple (_, y, _) = y -- you can use a wild card (_) to bypass naming an unused value +sndOfTriple (_, y, _) = y -- use a wild card (_) to bypass naming unused value -- Pattern matching on lists. Here `x` is the first element -- in the list, and `xs` is the rest of the list. We can write @@ -210,7 +210,7 @@ foo 5 -- 60 -- 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 --- the expression on its right is applied as the parameter to the function on its left. +-- the expression on its right is applied as parameter to function on its left. -- before even (fib 7) -- false -- cgit v1.2.3 From d063ea64694226c9490d5fe6da3b960449c3bfe3 Mon Sep 17 00:00:00 2001 From: Adam Bard Date: Wed, 1 Aug 2018 21:12:35 -0700 Subject: Restore lost articles I'm afraid we need these --- 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 e9ddf54d..90d47c27 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -210,7 +210,7 @@ foo 5 -- 60 -- 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 --- the expression on its right is applied as parameter to function on its left. +-- the expression on its right is applied as a parameter to the function on its left. -- before even (fib 7) -- false -- cgit v1.2.3 From f27686677752dca4d715f796aa0cc759bc05f998 Mon Sep 17 00:00:00 2001 From: David Sampson Date: Mon, 4 Nov 2019 10:51:48 -0600 Subject: Info on typeclasses and types --- haskell.html.markdown | 149 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 145 insertions(+), 4 deletions(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index 90d47c27..f3b84bdd 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -293,7 +293,13 @@ foldr (\x y -> 2*x + y) 4 [1,2,3] -- 16 -- 7. Data Types ---------------------------------------------------- --- Here's how you make your own data type in Haskell +-- A data type is declared with a 'type constructor' on the left +-- and one or more 'data constructors' on the right, separated by +-- the pipe | symbol. This is a sum/union type. Each data constructor +-- is a (possibly nullary) function that creates an object of the type +-- named by the type constructor. + +-- This is essentially an enum data Color = Red | Blue | Green @@ -304,7 +310,57 @@ say Red = "You are Red!" say Blue = "You are Blue!" say Green = "You are Green!" --- Your data types can have parameters too: +-- Note that the type constructor is used in the type signature +-- and the data constructors are used in the body of the function +-- Data constructors are primarily pattern-matched against + +-- This next one is a traditional container type holding two fields +-- In a type declaration, data constructors take types as parameters +-- Data constructors can have the same name as type constructors +-- This is common where the type only has a single data constructor + +data Point = Point Float Float + +-- This can be used in a function like: + +distance :: Point -> Point -> Float +distance (Point x y) (Point x' y') = sqrt $ dx + dy + where dx = (x - x') ** 2 + dy = (y - y') ** 2 + +-- Types can have multiple data constructors with arguments, too + +data Name = Mononym String | FirstLastName String String | FullName String String String + +-- To make things clearer we can use record syntax + +data Point2D = CartesianPoint2D { x :: Float, y :: Float } | PolarPoint2D { r :: Float, theta :: Float } + +myPoint = CartesianPoint2D { x = 7.0, y = 10.0 } + +-- Using record syntax automatically creates accessor functions (the name of the field) + +xOfMyPoint = x myPoint + +-- xOfMyPoint is equal to 7.0 + +-- Record syntax also allows a simple form of update + +myPoint' = myPoint { x = 9.0 } + +-- myPoint' is CartesianPoint2D { x = 9.0, y = 10.0 } + +-- Even if a type is defined with record syntax, it can be declared like +-- a simple data constructor. This is fine: + +myPoint'2 = CartesianPoint2D 3.3 4.0 + +-- It's also useful to pattern match data constructors in `case` expressions + +distanceFromOrigin x = case x of (CartesianPoint2D x y) -> sqrt $ x ** 2 + y ** 2 + (PolarPoint2D r _) -> r + +-- Your data types can have type parameters too: data Maybe a = Nothing | Just a @@ -313,8 +369,93 @@ Just "hello" -- of type `Maybe String` Just 1 -- of type `Maybe Int` Nothing -- of type `Maybe a` for any `a` +-- For convenience we can also create type synonyms with the 'type' keyword + +type String = [Char] + +-- Unlike `data` types, type synonyms need no constructor, and can be used +-- anywhere a synonymous data type could be used. Say we have the +-- following type synonyms and items with the following type signatures + +type Weight = Float +type Height = Float +type Point = (Float, Float) +getMyHeightAndWeight :: Person -> (Height, Weight) +findCenter :: Circle -> Point +somePerson :: Person +someCircle :: Circle +distance :: Point -> Point -> Float + +-- The following would compile and run without issue, even though it does not make +-- sense semantically, because the type synonyms reduce to the same base types + +distance (getMyHeightAndWeight somePerson) (findCenter someCircle) + +---------------------------------------------------- +-- 8. Typeclasses +---------------------------------------------------- + +-- Typeclasses are one way Haskell does polymorphism +-- They are similar to interfaces in other languages +-- A typeclass defines a set of functions that must work on any type that is in +-- that typeclass. + +-- The Eq typeclass is for types whose instances can be tested for equality with one another + +class Eq a where + (==) :: a -> a -> Bool + (/=) :: a -> a -> Bool + x == y = not (x /= y) + x /= y = not (x == y) + +-- This defines a typeclass that requires two functions, (==) and (/=) +-- It also declares that one function can be declared in terms of another +-- So it is enough that *either* the (==) function or the (/=) is defined +-- And the other will be 'filled in' based on the typeclass definition + +-- To make a type a member of a type class, the instance keyword is used + +instance Eq TrafficLight where + Red == Red = True + Green == Green = True + Yellow == Yellow = True + _ == _ = False + +-- Now we can use (==) and (/=) with TrafficLight objects + +canProceedThrough :: TrafficLight -> Bool +canProceedThrough t = t /= Red + +-- You can NOT create an instance definition for a type synonym + +-- Functions can be written to take typeclasses with type parameters, rather than types, +-- assuming that the function only relies on features of the typeclass + +isEqual (Eq a) => a -> a -> Bool +isEqual x y = x == y + +-- Note that x and y MUST be the same type, as they are both defined as being of type parameter 'a' +-- A typeclass does state that different types in the typeclass can be mixed together +-- So `isEqual Red 2` is invalid, even though 2 is an Int which is an instance of Eq, and Red is +-- a TrafficLight which is also an instance of Eq + +-- Other common typeclasses are: +-- Ord for types that can be ordered, allowing you to use >, <=, etc. +-- Read for types that can be created from a string representation +-- Show for types that can be converted to a string for display +-- Num, Real, Integral, Fractional for types that can do mathematical calculation +-- Enum for types that can be stepped through +-- Bounded for types with a maximum and minimum + +-- Haskell can automatically make types part of Eq, Ord, Read, Show, Enum, and Bounded +-- with the `deriving` keyword at the end of the type declaration + +data Point = Point Float Float deriving (Eq, Read, Show) + +-- In this case it is NOT necessary to create an 'instance' definition + ---------------------------------------------------- --- 8. Haskell IO +-- 9. Haskell IO ---------------------------------------------------- -- While IO can't be explained fully without explaining monads, @@ -395,7 +536,7 @@ main'' = do ---------------------------------------------------- --- 9. The Haskell REPL +-- 10. The Haskell REPL ---------------------------------------------------- -- Start the repl by typing `ghci`. -- cgit v1.2.3 From 35fc26b754a8696e505024c5b364d54e7adcde60 Mon Sep 17 00:00:00 2001 From: David Sampson Date: Mon, 4 Nov 2019 11:05:21 -0600 Subject: fixed line lengths --- haskell.html.markdown | 48 +++++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 19 deletions(-) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index f3b84bdd..1cc79ec9 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -330,15 +330,19 @@ distance (Point x y) (Point x' y') = sqrt $ dx + dy -- Types can have multiple data constructors with arguments, too -data Name = Mononym String | FirstLastName String String | FullName String String String +data Name = Mononym String + | FirstLastName String String + | FullName String String String -- To make things clearer we can use record syntax -data Point2D = CartesianPoint2D { x :: Float, y :: Float } | PolarPoint2D { r :: Float, theta :: Float } +data Point2D = CartesianPoint2D { x :: Float, y :: Float } + | PolarPoint2D { r :: Float, theta :: Float } myPoint = CartesianPoint2D { x = 7.0, y = 10.0 } --- Using record syntax automatically creates accessor functions (the name of the field) +-- Using record syntax automatically creates accessor functions +-- (the name of the field) xOfMyPoint = x myPoint @@ -357,8 +361,9 @@ myPoint'2 = CartesianPoint2D 3.3 4.0 -- It's also useful to pattern match data constructors in `case` expressions -distanceFromOrigin x = case x of (CartesianPoint2D x y) -> sqrt $ x ** 2 + y ** 2 - (PolarPoint2D r _) -> r +distanceFromOrigin x = + case x of (CartesianPoint2D x y) -> sqrt $ x ** 2 + y ** 2 + (PolarPoint2D r _) -> r -- Your data types can have type parameters too: @@ -386,8 +391,9 @@ somePerson :: Person someCircle :: Circle distance :: Point -> Point -> Float --- The following would compile and run without issue, even though it does not make --- sense semantically, because the type synonyms reduce to the same base types +-- The following would compile and run without issue, +-- even though it does not make sense semantically, +-- because the type synonyms reduce to the same base types distance (getMyHeightAndWeight somePerson) (findCenter someCircle) @@ -397,10 +403,11 @@ distance (getMyHeightAndWeight somePerson) (findCenter someCircle) -- Typeclasses are one way Haskell does polymorphism -- They are similar to interfaces in other languages --- A typeclass defines a set of functions that must work on any type that is in --- that typeclass. +-- A typeclass defines a set of functions that must +-- work on any type that is in that typeclass. --- The Eq typeclass is for types whose instances can be tested for equality with one another +-- The Eq typeclass is for types whose instances can +-- be tested for equality with one another. class Eq a where (==) :: a -> a -> Bool @@ -428,27 +435,30 @@ canProceedThrough t = t /= Red -- You can NOT create an instance definition for a type synonym --- Functions can be written to take typeclasses with type parameters, rather than types, --- assuming that the function only relies on features of the typeclass +-- Functions can be written to take typeclasses with type parameters, +-- rather than types, assuming that the function only relies on +-- features of the typeclass isEqual (Eq a) => a -> a -> Bool isEqual x y = x == y --- Note that x and y MUST be the same type, as they are both defined as being of type parameter 'a' --- A typeclass does state that different types in the typeclass can be mixed together --- So `isEqual Red 2` is invalid, even though 2 is an Int which is an instance of Eq, and Red is --- a TrafficLight which is also an instance of Eq +-- Note that x and y MUST be the same type, as they are both defined +-- as being of type parameter 'a'. +-- A typeclass does not state that different types in the typeclass can +-- be mixed together. +-- So `isEqual Red 2` is invalid, even though 2 is an Int which is an +-- instance of Eq, and Red is a TrafficLight which is also an instance of Eq -- Other common typeclasses are: -- Ord for types that can be ordered, allowing you to use >, <=, etc. -- Read for types that can be created from a string representation -- Show for types that can be converted to a string for display --- Num, Real, Integral, Fractional for types that can do mathematical calculation +-- Num, Real, Integral, Fractional for types that can do math -- Enum for types that can be stepped through -- Bounded for types with a maximum and minimum --- Haskell can automatically make types part of Eq, Ord, Read, Show, Enum, and Bounded --- with the `deriving` keyword at the end of the type declaration +-- Haskell can automatically make types part of Eq, Ord, Read, Show, Enum, +-- and Bounded with the `deriving` keyword at the end of the type declaration data Point = Point Float Float deriving (Eq, Read, Show) -- cgit v1.2.3 From aa8d8e408a8d9cce66de273a8689a9e38d9f5134 Mon Sep 17 00:00:00 2001 From: Spencer Burris Date: Thu, 15 Oct 2020 12:29:37 -0700 Subject: [Haskell/en] Explain the !! operator --- haskell.html.markdown | 2 ++ 1 file changed, 2 insertions(+) (limited to 'haskell.html.markdown') diff --git a/haskell.html.markdown b/haskell.html.markdown index 1cc79ec9..328da5c9 100644 --- a/haskell.html.markdown +++ b/haskell.html.markdown @@ -61,6 +61,8 @@ not False -- True -- A string is a list of characters ['H', 'e', 'l', 'l', 'o'] -- "Hello" + +-- Lists can be indexed with the `!!` operator followed by an index "This is a string" !! 0 -- 'T' -- cgit v1.2.3