Skip to content
This repository has been archived by the owner on Jun 13, 2020. It is now read-only.

Latest commit

 

History

History
20 lines (14 loc) · 727 Bytes

5956fd49.md

File metadata and controls

20 lines (14 loc) · 727 Bytes
title date
GADT
2020-05-25

The key point about GADTs is that pattern matching causes type refinement.

-- GHC User Guide

An example GADT:

data Query result where 
  Query_NotesByTag :: Tag -> Query [Note]
  Query_AllTags :: Query [Tag]

Pattern matching on the GADT constructor causes type refinement. For example, pattern matching on the constructor Query_NotesByTag refines the type (of the query result) to [Note]. GADTs are extremely useful for this purpose, something that cannot be achieved with regular ADTs (algebraic data types).

<z:zettels?tag=gadt>