Skip to content

Instantly share code, notes, and snippets.

@sordina
Created April 9, 2015 04:37
Show Gist options
  • Select an option

  • Save sordina/053a4129d7c3e8a63596 to your computer and use it in GitHub Desktop.

Select an option

Save sordina/053a4129d7c3e8a63596 to your computer and use it in GitHub Desktop.
Generate diagrams of your Haskell data-type interrelationships with this robust and elegant program!
#!/bin/bash
echo 'digraph {'
data="$(grep '^data' Prototype.hs | sed 's/data //; s/ .*//')"
for i in $data
do
echo "$i;"
targets="$(grep "data $i .*=" Prototype.hs -A 6 \
| sed '/^$/,$d' \
| grep '::' \
| sed 's/.*:: //; s/Maybe //; s/J.Value//; s/String//; s/ .*//')"
for j in $targets
do
echo "$i -> $j;"
done
done
types="$(grep '^type' Prototype.hs | grep -v '^type Lookup' | sed 's/type //; s/ .*//')"
for i in $types
do
echo "$i;"
targets="$(grep "type $i .*=" Prototype.hs \
| sed 's/^.*= //' \
| sed 's/[[:<:]]M.Map[[:>:]]/ /g' \
| sed 's/[[:<:]]J.Value[[:>:]]/ /g' \
| sed 's/[[:<:]]String[[:>:]]/ /g' \
| sed 's/[[:<:]]Int[[:>:]]/ /g' \
| sed 's/[[:<:]]Lookup[[:>:]]/ /g')"
for j in $targets
do
echo "$i -> $j;"
done
done
echo '}'
@sordina

sordina commented Apr 9, 2015

Copy link
Copy Markdown
Author

RAML Spec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment