Add New Haskell Cheat Sheet #3711
Changes from 6 commits
13ede39
61568eb
2f3ff25
5d8cd63
3e3b4a7
5cf7615
c627022
961feea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
}, | ||
{ | ||
"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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, but how should I call it/describe it otherwise? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]]", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Show guards. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand what I need to add here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guards restrict which values pass through the (monadic) comprehension. For example |
||
"val": "List comprehension" | ||
} | ||
], | ||
"Tuples": [ | ||
{ | ||
"key": "fst (True, 'A')", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the name and type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, I don't understand what you want me to replace. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"val": "Accesses the first element of a tuple (only works on pair)" | ||
}, | ||
{ | ||
"key": "snd (True, 'A')", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" | ||
} | ||
] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this.