Add New Haskell Cheat Sheet #3711
Add New Haskell Cheat Sheet #3711
Conversation
@napnac Thanks for the pull request! Unfortunately, we're only accepting contributions and improvements to a limited portion of the search space. The staff and community are currently focused on making DuckDuckGo the best search engine for programmers. To ensure we're making as much progress as possible, we are only accepting Instant Answers and updates related to the programming mission. If this is not related to the Programming Mission, it will likely be closed but you can:
If this is related to the Programming Mission, it will be reviewed by staff and the community as soon as possible! |
Haskell Cheat SheetDescription: When you search for "haskell cheat sheet," you should get a cheat sheet about the Haskell Language. Example Query: Haskell Cheat Sheet Tab Name: Cheat Sheet Source: These are the important fields from the IA page. Please check these for errors or missing information and update the IA page This is an automated message which will be updated as changes are made to the IA page |
}, | ||
{ | ||
"key": "1.42", | ||
"val": "Floating Point" |
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.
Float
(or Double
, or other Fractional
).
}, | ||
{ | ||
"key": "'a'", | ||
"val": "Character" |
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.
Char
}, | ||
{ | ||
"key": "True", | ||
"val": "Boolean" |
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.
Bool
}, | ||
{ | ||
"key": "[1, 2, 3]", | ||
"val": "List" |
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.
[Int]
}, | ||
{ | ||
"key": "(1, 4.2)", | ||
"val": "Tuple" |
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.
(Int, Float)
@napnac I think you should approach this cheat sheet from a different point of view; instead of mentioning specific use-cases for some of the basic functions, I think it would be more helpful to cover the basic, common AlgDTs and their uses, along with some of the typeclasses. |
@GuiltyDolphin Absolutely! But this cheat sheet right now is the bare minimum since there was none for Haskell. We can totally add more things to it in the future :) |
"val": "(Int, Float)" | ||
} | ||
], | ||
"Basic Operations": [ |
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.
I think it would be more useful to mention the Fractional
, Integral
, and Num
type classes; operators in the arithmetical sense are pretty easy to figure out.
"val": "Integer division" | ||
} | ||
], | ||
"Comparators": [ |
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.
As above, but with Ord
and Eq
.
"val": "Prints the string \"Hello!\"" | ||
}, | ||
{ | ||
"key": "input <- getLine", |
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.
Just use getLine
, this makes no sense without the notion of 'do' notation.
], | ||
"Enumerations": [ | ||
{ | ||
"key": "[1 .. 5]", |
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.
We can probably just mention the syntaxes of [start..]
, [start,next..stop]
, and [start..stop]
.
"val": "Infinite list of integers greater than or equal to 1" | ||
} | ||
], | ||
"Lists": [ |
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.
I think we should mention list comprehensions.
], | ||
"Functions": [ | ||
{ | ||
"key": "func params", |
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.
f x y ...
], | ||
"Control Flow": [ | ||
{ | ||
"key": "str = if a < b then \"yes!\" else \"no\"", |
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.
Just use if cond then x else y
.
Thanks for all feedbacks @GuiltyDolphin ! For your first two changes, should I add them in addition of what I already wrote or should I replace it ? |
@napnac I think replacement would be better, but you could provide a (small) example of usage. |
@GuiltyDolphin I only redid the 'Basic Operations' part because I didn't exactly know what you expected. I'm waiting for you feedbacks to start on the 'Comparators' part ;) |
}, | ||
{ | ||
"key": "Num Int", | ||
"val": "Num's instance for integer" |
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.
}, | ||
{ | ||
"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 comment
The reason will be displayed to describe this comment to others. Learn more.
Numeric addition.
}, | ||
{ | ||
"key": "4.2 :: Fractional a => a", | ||
"val": "Example of Fractional class" |
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.
}, | ||
{ | ||
"key": "2 :: Num a => a", | ||
"val": "Example of Num class" |
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.
}, | ||
{ | ||
"key": "[start..]", | ||
"val": "Infinite list" |
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.
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 comment
The 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 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).
"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 comment
The 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 comment
The 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 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]
.
], | ||
"Tuples": [ | ||
{ | ||
"key": "fst (True, 'A')", |
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.
Use the name and type.
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.
Again, I don't understand what you want me to replace. (Boolean, Char)
?
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.
fst : (a, b) -> a
.
"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 comment
The reason will be displayed to describe this comment to others. Learn more.
As above.
}, | ||
{ | ||
"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 comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need to say the bit in parens.
Automated screenshot from beta.duckduckgo.com |
Thanks for the help @GuiltyDolphin ! I added another example of list comprehension with guards instead of overloading the first one, tell me if the rest is fine. ;) |
Automated screenshot from beta.duckduckgo.com |
@napnac thanks for the awesome work. @GuiltyDolphin the changes are now live on Beta: https://beta.duckduckgo.com/?q=Haskell+Cheat+Sheet&ia=cheatsheet Any more updated needed? If not please merge! |
Automated screenshot from [beta.duckduckgo.com](https://beta.duckduckgo.com/?q=Haskell Cheat Sheet) |
Automated screenshot from [beta.duckduckgo.com](https://beta.duckduckgo.com/?q=Haskell Cheat Sheet) |
ping @GuiltyDolphin. Is this good to merge? |
For code LGTM but I can't view it on beta even though it's active. https://beta.duckduckgo.com/?q=Haskell+cheat+sheet It seems like the software IA is triggered instead. Also tried aliases + "cheat sheet" and it didn't trigger. |
There must be something funky going on with Beta here, I can't get this cheatsheet to show either |
Looks fine on duckpan, thanks @napnac |
Type of Change
Description of new Instant Answer, or changes
New cheat sheet for the Haskell language including basic features (data types, operations, comparators, IO, enumerations, lists, tuples, functions, control flow).
Related Issues and Discussions
People to notify
IA Page: https://duck.co/ia/view/haskell_cheat_sheet