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

Conversation

haltode
Copy link
Contributor

@haltode haltode commented Oct 23, 2016

Type of Change

  • New Instant Answer
    • Cheat Sheet
  • Improvement
    • Bug fix
    • Enhancement
  • Non–Instant Answer
    • Other (Role, Template, Test, Documentation, etc.)

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

@daxtheduck
Copy link

@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:

  1. Help us prevent further confusion by telling us where you found out about DuckDuckHack or where we could've alerted you earlier.
  2. Keep this code handy! We'll be expanding into other search topics in the future!
  3. Join us at our new home: https://forum.duckduckhack.com/

If this is related to the Programming Mission, it will be reviewed by staff and the community as soon as possible!

@daxtheduck
Copy link

daxtheduck commented Oct 23, 2016

Haskell Cheat Sheet

Description: 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"
Copy link
Member

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"
Copy link
Member

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"
Copy link
Member

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"
Copy link
Member

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"
Copy link
Member

Choose a reason for hiding this comment

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

(Int, Float)

@GuiltyDolphin
Copy link
Member

@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.

@haltode
Copy link
Contributor Author

haltode commented Oct 23, 2016

@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": [
Copy link
Member

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": [
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, but with Ord and Eq.

"val": "Prints the string \"Hello!\""
},
{
"key": "input <- getLine",
Copy link
Member

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]",
Copy link
Member

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": [
Copy link
Member

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",
Copy link
Member

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\"",
Copy link
Member

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.

@haltode
Copy link
Contributor Author

haltode commented Oct 23, 2016

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 ?

@GuiltyDolphin
Copy link
Member

@napnac I think replacement would be better, but you could provide a (small) example of usage.

@haltode
Copy link
Contributor Author

haltode commented Oct 27, 2016

@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"
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": "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": "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": "[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).

"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].

],
"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.

},
{
"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.

@daxtheduck daxtheduck deployed to beta.duckduckgo.com October 28, 2016 08:45 Active
@daxtheduck
Copy link

Automated screenshot from beta.duckduckgo.com

Mobile screenshot

@daxtheduck daxtheduck deployed to beta.duckduckgo.com October 29, 2016 10:59 Active
@haltode
Copy link
Contributor Author

haltode commented Oct 29, 2016

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. ;)

@daxtheduck
Copy link

Automated screenshot from beta.duckduckgo.com

Mobile screenshot

@moollaza moollaza changed the title New cheat sheet : Haskell New Haskell Cheat Sheet Nov 9, 2016
@daxtheduck daxtheduck deployed to beta.duckduckgo.com November 9, 2016 16:46 Active
@moollaza
Copy link
Member

moollaza commented Nov 9, 2016

@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!

@moollaza moollaza changed the title New Haskell Cheat Sheet Add New Haskell Cheat Sheet Nov 9, 2016
@daxtheduck daxtheduck deployed to beta.duckduckgo.com November 9, 2016 16:58 Active
@daxtheduck
Copy link

Automated screenshot from [beta.duckduckgo.com](https://beta.duckduckgo.com/?q=Haskell Cheat Sheet)

Mobile screenshot

@daxtheduck
Copy link

Automated screenshot from [beta.duckduckgo.com](https://beta.duckduckgo.com/?q=Haskell Cheat Sheet)

Mobile screenshot

@daxtheduck daxtheduck deployed to beta.duckduckgo.com December 20, 2016 14:08 Active
@pjhampton
Copy link
Contributor

ping @GuiltyDolphin. Is this good to merge?

@kirkins
Copy link
Contributor

kirkins commented Jul 10, 2017

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.

@mintsoft
Copy link
Collaborator

There must be something funky going on with Beta here, I can't get this cheatsheet to show either

@mintsoft mintsoft merged commit 9a58227 into duckduckgo:master Aug 23, 2017
@mintsoft
Copy link
Collaborator

Looks fine on duckpan, thanks @napnac

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants