Skip to content

Instantly share code, notes, and snippets.

@rightfold
Last active October 10, 2015 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rightfold/ab3e534287ed33fcd9ca to your computer and use it in GitHub Desktop.
Save rightfold/ab3e534287ed33fcd9ca to your computer and use it in GitHub Desktop.
-- in Haskell, you can do this:
data T =
A
| B
-- or this:
data T
= A
| B
-- but not this:
data T =
| A -- note leading "|"
| B
-- which makes sorting/diffs/merging a nightmare
-- this preprocessor fixes that. just invoke the Haskell
-- compiler with "-F -pgmF ./preprocessor.pl"
#!/usr/bin/env perl
use strict;
use warnings;
shift @ARGV;
open my $in, '<', shift(@ARGV);
open my $out, '>', shift(@ARGV);
my $data_decl_start = 0;
while (<$in>) {
if ($data_decl_start) {
s/^\s+\|//;
$data_decl_start = 0;
} elsif (/^data .*?=$/) {
$data_decl_start = 1;
}
print $out $_;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment