-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.hs
34 lines (27 loc) · 842 Bytes
/
Main.hs
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
26
27
28
29
30
31
32
33
34
import HaltaVista.Types
import HaltaVista.TypeInference
import HaltaVista.Hoogle
import HaltaVista.Match
import Control.Monad(filterM, when)
suffix = reverse . takeWhile (/= '.') . reverse
search :: [([Input], Output)] -> IO [Answer]
search ios = do
mty <- infer ios
case mty of
Left e -> error (show e)
Right ty -> do
--putStrLn ("ty = " ++ (suffix ty))
hoogle (suffix ty)
split xs = split' [] xs
where split' acc [x] = (reverse acc,x)
split' acc (x:xs) = split' (x:acc) xs
parse :: String -> [([Input], Output)]
parse = map split . map words . lines
pretty :: Answer -> String
pretty (x,y) = x ++ " " ++ y
main = do
ios <- parse `fmap` getContents
candidates <- search ios
let pp cand = do ok <- matches cand ios
when ok $ putStrLn $ pretty cand
mapM_ pp candidates