background preloader

The Haskell Cheatsheet

The Haskell Cheatsheet

Apprendre Haskell vous fera le plus grand bien ! - Fonctions d’ordre supérieur Les fonctions Haskell peuvent prendre d’autres fonctions en paramètres, et retourner des fonctions en valeur de retour. Une fonction capable d’une de ces deux choses est dite d’ordre supérieur. Les fonctions d’ordre supérieur ne sont pas qu’une partie de l’expérience Haskell, elles sont l’expérience Haskell. Elles s’avèrent indispensable pour définir ce que les choses sont plutôt que des étapes qui changent un état et bouclent. Fonctions curryfiées En Haskell, toutes les fonctions ne prennent en fait qu’un unique paramètre. ghci> max 4 55ghci> (max 4) 55 Mettre un espace entre deux choses consiste à appliquer une fonction. En quoi cela nous aide-t-il ? Regardons cette fonction violemment simple : multThree :: (Num a) => a -> a -> a -> amultThree x y z = x * y * z Que se passe-t-il vraiment quand on fait multThree 3 5 9 ou ((multThree 3) 5) 9 ? ghci> let multTwoWithNine = multThree 9ghci> multTwoWithNine 2 354ghci> let multWithEighteen = multTwoWithNine 2ghci> multWithEighteen 10180 Yo !

Haskell Haskell is a functional programming language. If you are a seasoned programmer, consult the overview to see what makes Haskell unique and different from other languages. Haskell is distinct in a few ways: Haskell is pure. Haskell is enjoyable to use because dealing with pure functions makes code much easier to reason about, and the advanced type system helps catch silly and profound mistakes. Our aim in this book is to introduce you to the Haskell programming language — from the very basics to advanced features — and to computer programming in general. Overview[edit] The book is divided into a Beginner's Track, an Advanced Track, and a section called Haskell in Practice which covers more day-to-day issues and uses mostly items from the Beginner's Track. Search[edit] You may search the book here: Beginner's Track[edit] Our aim in this track is to introduce you to Haskell basics and some commonly used libraries. Advanced Track[edit] Haskell in Practice[edit] Appendices[edit] About the book[edit]

Haskell « A Critical Systems Blog Looking to make a statement this holiday season? You could try to win the office “ugly holiday sweater” contest. Or, you could play “Jingle Bells” on your Arduino microcontroller, using Haskell. This post is about the latter. We’re going to write this small program using the Copilot embedded domain-specific language (on Hackage and the source on Github). (For the impatient, the Haskell file is here, and the generated .c and .h files are here and here, respectively.) We’re going to essentially recreate this C/Wiring program, plus flash some LEDs, but hopefully in a easier, safer way. Determine the note and number of beats to play.Play the piezo speaker.Flash the LEDs. We’ll start by defining which pins control what function: -- pin numbers speaker, red, green :: Spec Int32 speaker = 13 red = 12 green = 11 The type Spec Int32 takes an Int32 and lifts it into a Copilot expression. We’ll call the program cycleSong. Now for the actual program: And that’s basically it. x = [0] ++ map (+1) x

CIS 194 Mondays 1:30-3Towne 309 Class Piazza site Instructor: Brent Yorgey Email: byorgey at cisOffice: Levine 513Office hours: Friday 2-4pm TAs: Adi Dahiya (office hours: Thursdays 1-3pm, Moore 100)Zach Wasserman (office hours: Thursdays 12-1pm, Moore 100) Haskell is a high-level, pure functional programming language with a strong static type system and elegant mathematical underpinnings, and is being increasingly used in industry by organizations such as Facebook, AT&T, and NASA. Screencasts Yesod 1.4 Making a blog with Yesod, using Yesod 1.4 by Max Tagher. Source code for this screencast is available on Github. Yesod 1.0 Yesod 1.0 Introductory Screencast from Michael Snoyman on Vimeo. Older Screencasts Some of the specific details shown here may be slightly out of date. Yammer (Twitter clone) Introduction to Yesod Web Framework 0.5 Hello World Blog, part 1 Blog Tutorial - Part 1 - Yesod Web Framework 0.4.0 from Michael Snoyman on Vimeo. Here's the source code: Blog, part 2 Blog Tutorial - Part 2 - Yesod Web Framework 0.4.0 from Michael Snoyman on Vimeo.

Sifflet Tutorial Gregory D. Weber August 12, 2013 Sifflet Version 2.2 Just as water flows through rivers, and as rivers flow into other rivers and join their waters, so data flows through channels and mingles with other flows of data. In Unix (including Macintosh OS X), start Sifflet by typing this command into a terminal in an X Window session: sifflet or, if you want to be able to continue using your terminal before Sifflet finishes: sifflet & In Microsoft Windows, using Windows Explorer, navigate to the folder containing sifflet.exe and double-click on it. Alternately, in Microsoft Windows, launch CMD, navigate to the folder containing sifflet.exe, and type A company sells two products, A and B, and makes a gross profit of $0.12 per unit of product A and $0.25 per unit of product B. When you start Sifflet, it will open two windows: the Function Pad window and the Workspace window. Figure 1. Figure 1. Figure 2. Figure 2. This diagram shows a function named grossProfit. Figure 3. Figure 3. Figure 4. Figure 4.

Haskell: The Confusing Parts If you’re used to the C family of languages, or the closely related family of “scripting languages,” Haskell’s syntax (mainly) is a bit baffling at first. For some people, it can even seem like it’s sneaking out from under you every time you think you understand it. This is sort of a FAQ for people who are new to Haskell, or scared away by its syntax. Use this as a cheat sheet, not a textbook. Misc. Stuff You Should Know Already Quick review, because if you’ve heard of Haskell, you should also have heard of most of this. foo :: Bar baz -> Bar quux is a type signature for the function foo, where Bar baz is the type of argument it takes, and Bar quux is the type of the return value. There’s no null and no void. Haskell’s syntax is indirectly based on ML, so if you stop reading here and go learn OCaml instead, some of this information will still be kinda useful. Type Names and Constructors The “has type” (::) operator can appear as an expression in parentheses, or a separate declaration.

Haskell comme un vrai! tlpl: Un tutoriel très court mais très dense pour apprendre Haskell. Merci à Oleg Taykalo vous pouvez trouver une traduction Russe ici: Partie 1 & Partie 2 ; Table of Content Je pense vraiment que tous les développeurs devraient apprendre Haskell. Peut-être pas devenir des ninjas d’Haskell, mais au moins savoir ce que ce langage a de particulier. Son apprentissage ouvre énormément l’esprit. La plupart des langages partagent les mêmes fondamentaux : les variablesles bouclesles pointeursles structures de données, les objets et les classes Haskell est très différent. Plier son esprit à Haskell peut être difficile. Cet article sera certainement difficile à suivre. La manière conventionnelle d’apprendre Haskell est de lire deux livres. Cet article fait un résumé très dense et rapide des aspect majeurs d’Haskell. Pour les francophones ; je suis désolé. Cet article contient cinq parties : 01_basic/10_Introduction/00_hello_world.lhs Introduction Install Tools: Don’t be afraid ~ runhaskell . Functional In C:

Lenses In Pictures - adit.io You should know what a functor is before reading this post. Read this to learn about functors. Suppose you want to make a game: Ok, now how would you move this player? moveX (Mario (Point xpos ypos)) val = Mario (Point (xpos + val) ypos) Instead, lenses allow you to write something like this: location.x `over` (+10) $ player1 Or this is the same thing: over (location . x) (+10) player1 Lenses allow you to selectively modify just a part of your data: Much clearer! location is a lens. Fmap You probably know how fmap works, Doctor Watson (read this if you don’t): Well old chap, what if you have nested functors instead? You need to use two fmaps! Now, you probably know how function composition works: What about function composition composition? “If you want to do function composition where a function has two arguments”, says Sherlock, “you need (.).(.)!” “That looks like a startled owl”, exclaims Watson. “Indeed. The type signature for function composition is: (.) :: (b -> c) -> (a -> b) -> (a -> c) Setters

Related: