One of the things I like about the new Apple language Swift is that it combines procedural programming with algebraic data types. What other languages do this?


3 Answers 3


ML family: OCaml, SML, F#

ML was (AFAIK) the first language to directly support algebraic data types; ML and its descendants have always at least had mutable state through reference variables.


Within the Racket family there is #lang plai which directly provides algebraic types.

#lang racket supports the same style of program using multiple subtypes of a struct type and using the match macro. There's a good talk on the relationship between algebraic types and this design in this talk, part of the Brown online PL course.

Typed Racket provides explicit union types and matching through the match macro.


Scala's case classes are algebraic types built on top of the JVM's class system.


Wikipedia has a list of languages with algebraic data types; languages on this list with mutability include Nemerle and haXe.

I've conflated match style operations with algebraic datatypes here, partly because convenience is really all that separates some of these languages from assembly; you can define ad-hoc algebraic types in any language you like, it just won't be very nice.

  • Thanks, that wikipedia page was pretty much what I was looking for. Appreciate it! Jul 1, 2014 at 17:42

You can go full imperative in ML-family languages (e.g. Ocaml) while enjoying ADTs and pattern matching.

You can have a sort of ADT in Algol descendants like C and Pascal by using variant records. But you will get very little syntactic sugar. You'll have to pack/unpack and check the variants manually, without the static type safety that e.g. Haskell would give you.


Java/C# don't support ADTs out of the box but with some boilerplate and lambdas you can pull it off.

If I'm not mistaken that's also pretty much what Scala's case classes are, minus the boilerplate.

  • Yes, Scala case classes are used to model algebraic data types. +1
    – Giorgio
    Jun 30, 2014 at 18:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.