Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Add New Haskell Cheat Sheet #3711

Merged
merged 8 commits into from Aug 23, 2017
Merged
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
202 changes: 202 additions & 0 deletions share/goodie/cheat_sheets/json/haskell.json
@@ -0,0 +1,202 @@
{
"id": "haskell_cheat_sheet",
"name": "Haskell",
"description": "Overview of Haskell syntax and common features",

"metadata": {
"sourceName": "Haskell",
"sourceUrl" : "https://www.haskell.org/"
},

"aliases": [
"haskell language",
"hs"
],

"template_type": "code",

"section_order": [
"Data Types",
"Basic Mathematical Operations",
"Comparators",
"IO",
"Enumerations",
"Lists",
"Tuples",
"Functions",
"Control Flow"
],

"sections": {
"Data Types": [
{
"key": "1",
"val": "Integer"
},
{
"key": "1.42",
"val": "Float"
},
{
"key": "\"abc\"",
"val": "String"
},
{
"key": "'a'",
"val": "Char"
},
{
"key": "True",
"val": "Bool"
},
{
"key": "[1, 2, 3]",
"val": "[Int]"
},
{
"key": "(1, 4.2)",
"val": "(Int, Float)"
}
],
"Basic Mathematical Operations": [
{
"key": "Num",
"val": "Basic numeric typeclass"
},
{
"key": "Num Int",
"val": "Num's instance for integer"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this.

},
{
"key": "Integral",
"val": "Numeric typeclass including integral numbers"
},
{
"key": "Fractional",
"val": "Numeric typeclass including fractional numbers (supports real division)"
},
{
"key": "2 :: Num a => a",
"val": "Example of Num class"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this.

},
{
"key": "4.2 :: Fractional a => a",
"val": "Example of Fractional class"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this.

},
{
"key": "(+) :: Num a => a -> a -> a",
"val": "Example of a basic operation"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Numeric addition.

},
{
"key": "(/) :: Fractional a => a -> a -> a",
"val": "Division"
},
{
"key": "div :: Integral a => a -> a -> a",
"val": "Integer division"
}
],
"Comparators": [
{
"key": "A == B",
"val": "A is equal to B"
},
{
"key": "A /= B",
"val": "A is not equal to B"
},
{
"key": "A < B",
"val": "A is less than B"
},
{
"key": "A <= B",
"val": "A is less than or equal to B"
},
{
"key": "A > B",
"val": "A is greater than B"
},
{
"key": "A >= B",
"val": "A is greater than or equal to B"
}
],
"IO": [
{
"key": "putStrLn \"Hello!\"",
"val": "Prints the string \"Hello!\""
},
{
"key": "getLine",
"val": "Reads the input"
}
],
"Enumerations": [
{
"key": "[start..stop]",
"val": "Creates a list containing all values between start and stop"
},
{
"key": "[start,next..stop]",
"val": "Same as above but with a different step"
},
{
"key": "[start..]",
"val": "Infinite list"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not always infinite (in fact, will usually be finite). It depends on the Enum implementation for the DT.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but how should I call it/describe it otherwise?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just say that it iterates from 'start' to the maximum bound (if any).

}
],
"Lists": [
{
"key": "[]",
"val": "Empty list"
},
{
"key": "[1, 2, 3] !! 1",
"val": "Returns the first element of the list"
},
{
"key": "[1, 2] ++ [3, 4]",
"val": "Joins the two lists together"
},
{
"key": "'A' : ['B', 'C']",
"val": "Adds the letter A to the head of the list"
},
{
"key": "[x + y | x <- [1,2], y <- [1..5]]",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show guards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what I need to add here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guards restrict which values pass through the (monadic) comprehension. For example [x | x <- [1..10], x > 7] would be equivalent to [8, 9, 10].

"val": "List comprehension"
}
],
"Tuples": [
{
"key": "fst (True, 'A')",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the name and type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I don't understand what you want me to replace. (Boolean, Char)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fst : (a, b) -> a.

"val": "Accesses the first element of a tuple (only works on pair)"
},
{
"key": "snd (True, 'A')",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

"val": "Accesses the second element of a tuple (only works on pair)"
}
],
"Functions": [
{
"key": "f x y ...",
"val": "Calls a function with the given parameters"
},
{
"key": "func x y = x + y",
"val": "Declaration of a simple function that adds two variables"
},
{
"key": "(\\x y -> x + y) 2 3",
"val": "Anonymous function that adds two variables (here we use the numbers 2 and 3 as an example)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to say the bit in parens.

}
],
"Control Flow": [
{
"key": "if cond then x else y",
"val": "If expression"
}
]
}
}