Skip to content

Instantly share code, notes, and snippets.

@Babali42
Last active July 10, 2025 09:54
Show Gist options
  • Save Babali42/d09bbb3951d644b74f53fcdbd122ecf9 to your computer and use it in GitHub Desktop.
Save Babali42/d09bbb3951d644b74f53fcdbd122ecf9 to your computer and use it in GitHub Desktop.
Haskell Cheat Sheet

Haskell Cheat Sheet

Comment créer un programme :

main = do print "Hello World !"

Compiler le programme et exécuter l'exécutable

Glagow Haskell Compiler

ghc test.hs

./test

Compiler le programme (load) et l'exécuter en interactive

Glagow Haskell Compiler Interactive

ghci

:l test.hs

test

Pour quitter le ghci c'est :q

Créer un module et exporter une fonction

module LIb (somefunc) where

somefunc :: IO()
somefunc = putStrLn "SomeFunc"
module Main where

import Lib

main :: IO()
main = someFunc

Types on the atomic level

Bool
Char
Integer
Int
Float
Double

propagation des types

kilo :: Int
kilo = 1000

mega :: Int
mega = kilo ^ (2::Int) //will be an int, numeric operation typically consume and produce values of the same type

Liste

intList ::  [Int]
intList = [1, 2, 3]

Tuples

At least two values joined, no maximum

intCharDoubleTriple :: (Int, Char, Double)
intCharDoubleTriple :: (1, 'a', 2)

Function avec des calculs intermédiaires

module Darts (score) where

score :: Float -> Float -> Int
score x y
    | distance > 10 = 0
    | distance > 5  = 1
    | distance > 1  = 5
    | otherwise     = 10
    where distance = sqrt(x^2 + y^2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment