background preloader

Tutos

Facebook Twitter

Mike's World-O-Programming - Yet Another Monad Tutorial (part 2: >>= and return) In the previous article I gave the conceptual background necessary to understand what monads are. Now I'm going to get into more of the details. The two fundamental monadic operations Remember when I said above that monads generalize function composition and function application? We'll work through that here. Have patience: it'll take a while. By this point, I hope you have at least a vague sense of what monads "are" and what they are used for. However, as I said before, one of the keys to functional programming is the ability to compose functions to create new functions. Let's say that we have two monadic functions: f :: a -> m b g :: b -> m c for some monad m.

F :: a -> IO b g :: b -> IO c but the same argument will apply for all monads. H :: a -> IO c i.e. a function that takes a value of type a, outputs a value of type c, and possibly does some I/O along the way (with the I/O somehow being the combination of the I/O activity for functions f and g). P :: a -> b q :: b -> c r :: a -> c and. Le Programmeur Moderne - Programmez en Haskell. Par gnomnain, dernière mise à jour le 19/12/2009 à 22:05:26 Ce tuto a pour but de vous apprendre à programmer en Haskell, un langage fonctionnel pur, avec un modèle d'évaluation paresseuse par défaut, typé statiquement (avec de l'inférence de types). Si vous ne savez pas ce qu'est Haskell, ou pourquoi apprendre à programmer dans ce langage, je vous conseille de passer directement au premier chapitre, qui répond à toutes ces questions.

Pour pouvoir suivre ce tuto, il n'est pas nécessaire d'avoir un niveau exceptionnel en programmation (même si ça ne peut qu'aider), mais il est conseillé de savoir faire un peu plus qu'un Hello World dans un autre langage. Si vous avez des remarques, n'hésitez pas à laisser des commentaires, ils seront pris en compte pour la version suivante. Ce tutoriel est aussi publié sur le site du zéro, mais cette version est plus rapidement à jour. Ce tutoriel est place sous licence Creative Commons BY-SA Haskell ? Premiers pas avec ghci Définir des fonctions Récursivité.

Autres langages. In 5 steps. Haskell is a general purpose, purely functional programming language. This page will help you get started as quickly as possible. 1 Install Haskell The recommended way to get started with programming Haskell is the Haskell Platform. The Platform comes with GHC, the de-facto standard Haskell compiler, with many useful tools that will let you program Haskell painlessly. Try Haskell provides a less complete but quicker way to give Haskell a shot. 2 Start Haskell If you have installed the Haskell Platform, open a terminal and type ghci (the name of the executable of the GHC interpreter) at the command prompt.

. $ ghci GHCi, version 6.12.3: :? And you are presented with a prompt. 3 Write your first Haskell program If you've learned to program another language, your first program probably was "Hello, world! " Prelude> "Hello, World! "" The Haskell system evaluated the string, and printed the result. Prelude> putStrLn "Hello World" Hello World main = putStrLn "Hello, World! " Learn You a Haskell for Great Good! - Starting Out. Ready, set, go! Alright, let's get started! If you're the sort of horrible person who doesn't read introductions to things and you skipped it, you might want to read the last section in the introduction anyway because it explains what you need to follow this tutorial and how we're going to load functions. The first thing we're going to do is run ghc's interactive mode and call some function to get a very basic feel for haskell.

Open your terminal and type in ghci. You will be greeted with something like this. GHCi, version 6.8.2: :? For help Loading package base ... linking ... done. GHCi, version 6.8.2: :? Congratulations, you're in GHCI! Here's some simple arithmetic. ghci> 2 + 15 17 ghci> 49 * 100 4900 ghci> 1892 - 1472 420 ghci> 5 / 2 2.5 ghci> ghci> 2 + 15 17 ghci> 49 * 100 4900 ghci> 1892 - 1472 420 ghci> 5 / 2 2.5 ghci> This is pretty self-explanatory. Pretty cool, huh? Boolean algebra is also pretty straightforward.

Yikes! . Real World Haskell.