aboutsummaryrefslogtreecommitdiffstats
path: root/autotypes/src/AutoTypes.hs
blob: ddc948c244becf620ebc21cce012071667232b5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module AutoTypes
  ( autoTypes,
    autoTypes',
  )
where

import qualified AutoTypes.Unify as U
import Data.Aeson (Value, decodeFileStrict', encode)
import Data.Maybe (fromJust)
import System.Environment (getArgs)
import System.FilePath (takeFileName)

autoTypes :: FilePath -> [FilePath] -> IO U.T
autoTypes fp fps = autoTypes' <$> go fp <*> mapM go (fp : fps)
  where
    go = fmap fromJust . decodeFileStrict'

autoTypes' :: Value -> [Value] -> U.T
autoTypes' t' ts' =
  let types = map U.fromJson (t' : ts')
   in head
        ( foldr1
            (\ls rs -> (concat [U.unify1 l r | l <- ls, r <- rs]))
            (map (: []) types)
        )