Description
TL;DR: Basically I'm looking for simple data modelling exercises that involve recursive custom data types (not general-purpose ones from the standard library, like Data.List
or Data.Tree
) -- they may however have type parameters -- with multiple constructors and possibly multiple constructor parameters.
The long version: I want to create an overview of what coverage the concept of custom data types our current exercises has got. The purpose is to propose porting or creating exercises that cover the missing areas.
I went over all Haskell exercises using the following query:
exercism/haskell/exercises $ ack '^data' -A 10 --type=haskell --ignore-dir=examples --ignore-dir=test
and characterised their use of custom data types:
Exercise | Properties / Purpose | |
---|---|---|
space-age |
1 | Enum |
resistor-colors |
2 | Enum |
grade-school |
2 | newtype |
perfect-numbers |
2 | Enum |
nucleotide-count |
2 | Enum |
complex-numbers |
3 | Product, single type parameter |
triangle |
3 | Enum |
kindergarten-garden |
3 | Enum |
robot-simulator |
3 | Enum |
dnd-character |
3 | Records |
simple-linked-list |
4 | List, recursive |
all-your-base |
4 | Enum, error handling, single parameter |
meetup |
4 | Enum, uses Data.Time.Calendar |
largest-series-product |
4 | Enum, error handling |
matrix |
4 | Records |
clock |
4 | newtype |
allergies |
4 | Enum |
binary-search-tree |
5 | Binary tree, recursive |
custom-set |
5 | Binary tree or list, recursive |
linked-list |
6 | Binary tree (heh), recursive, uses concurrency |
sublist |
6 | Enum |
robot-name |
6 | newtype, uses concurrency |
zebra-puzzle |
7 | Enum |
bowling |
7 | Enum, error handling, records |
connect |
8 | Enum |
lens-person |
9 | Nested records, lenses |
go-counting |
9 | Enum |
zipper |
10 | Binary tree, recursive, tree zipper |
forth |
10 | Enum or AST, error handling, single parameter |
I then summarized this as the following categories:
- Data type is an enum, e.g.
space-age
(Mercury
,Venus
etc.) - Data type has a constructor with a parameter, e.g.
all-your-base
(InvalidDigit a
, etc.) - Data type has a constructor with two parameters, i.e.
complex-number
(Complex a a
) - Data type is a record (multiple named parameters), e.g.
dnd-character
(data Character = Character { ... }
) - Data type has nested records, i.e.
lens-person
(10) - Data type has a type parameter, e.g.
all-your-base
,complex-number
(data Error a = ...
,data Complex a = ...
) - Data type is a custom error type, e.g.
all-your-base
(4),largest-series-product
(4),bowling
(7),forth
(10) - Data type is a list, i.e. (
simple-linked-list
) - Data type is a binary tree, i.e.
binary-search-tree
,custom-set
,linked-list
,zipper
Without being scientific, I keep a number of factors in my head when considering whether an exercise is a bad fit for the core track or as an early side exercise: Too mathy, too difficult, too many subjects covered at once, re-implements standard library, refactoring exercise, ...
General-purpose lists don't go under "custom data types"; there is no standard-library binary tree, but it's covered plentifully already; in particular, binary-search-tree
is not too difficult and covers just one thing. Rose trees (Data.Tree
) are addressed in exercism/problem-specifications#1388 in a way that leaves room for both a custom data type implementation and a recommendation to base it on Data.Tree
instead.
So what I'd like are exercises that cover custom data types that aren't just enums, aren't just an error type, and aren't just single-constructor records, which we've covered pretty well already.
Here are some suggestions that new exercises that focus on custom data types could have:
- Data type that isn't error-handling with multiple constructors
- Data type that isn't error-handling with multiple constructor parameters
- Data type that isn't error-handling with one or more type parameters
- Data type that isn't re-implementation (list, binary tree) with recursive constructors
I remember an exercise from university on modelling certain types of acyclic, organic chemical bonds:
data Bond = C Bond Bond Bond Bond | H
So basically I'm looking for easy data modelling exercises that involve (possibly mutually) recursive custom data types (not general-purpose ones from the standard library, like Data.List
or Data.Tree
) -- they may however have type parameters -- with multiple constructors and possibly multiple constructor parameters.