Personal tools

Ce este tipul Either ?

From HaskellWiki

Revision as of 20:59, 30 September 2007 by Ha$kell (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Este un tip de date cu doua alternative (un fel de reuniune de doua tipuri - imaginati-va o capsula ca cea de Ampicilina in care fiecare parte ar fi umpluta cu altfel de substanta.)

Definitia formala este:

data Either r g = Left r | Right g deriving (Eq, Ord, Read, Show)

Deci capsulele Either fie ca sunt de dreapta (Right g) sau de stanga (Left r) au automat incluse (fiind generate de sistem) egalitatea, ordinea, citirile si scrierile.