A language to 'map' from AST to data types - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Sridhar Ratnakumar

Is there already a library or something that does this in an abstract manner?

I have a Markdown parsed into Pandoc AST. I want to "map" this AST into some custom structured data type. I want a "language" that can define this "map", to convert pandoc's AST to whatever custom type.

Here's an example,

## Feature 1
en
: This is a english description of feature 1
fr
: Ceci est une description française de la fonctionnalité 1

## Feature 2
en
: ...
fr
: ...

Imagine we have the Pandoc AST for the above Markdown (the translation table of each feature is represented in the AST as definition lists), and I'd like to write a "map" for converting it to the values of the following data type Features:

type Features = NonEmpty Feature

data Feature = Feature { unFeature :: Translated Text }

data Translated a = Map Lang a -- TODO: use non-empty map with default key

data Lang = EN | FR

How would you approach this problem more generally, so as to make it possible to support other output data types with minimal code (for mapping)?

The map should be strict, so as to fail on unexpected markdown uses (eg: don't want third level heading or blockquotes in the example above).

Advanced features that build on the basic Markdown syntax.