-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
20 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Data.Schema.Deinline (deinline) where | ||
|
||
import Control.Arrow (first) | ||
import Data.Fix (Fix (..), foldFix) | ||
import Data.List (nub) | ||
import Data.Schema (Schema, SchemaF (..), Type (..)) | ||
|
||
deinline :: Schema -> Schema | ||
deinline = fst . foldFix getTypes | ||
|
||
getTypes :: SchemaF (Schema, [Schema]) -> (Schema, [Schema]) | ||
getTypes (Atom ty) = (Fix . Atom $ ty, []) | ||
getTypes (Sum dt@(Just (_, ty)) cons) = (Fix . Atom . TyName $ ty, Fix (Sum dt (map fst cons)) : concatMap snd cons) | ||
getTypes (Prod fields) = (Fix . Prod . map fst $ fields, concatMap snd fields) | ||
getTypes (Field name ty) = first (Fix . Field name) ty | ||
getTypes (Con name ty) = first (Fix . Con name) ty | ||
getTypes (List ty) = first (Fix . List) ty | ||
getTypes (Schema mods) = (Fix . Schema . nub . concatMap snd $ mods, []) | ||
getTypes x = error $ "unhandled: " <> show x |