-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathPointfree.hs
31 lines (27 loc) · 855 Bytes
/
Pointfree.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
module Pointfree where
import Plugin.Pl.Common (mapTopLevel, mapTopLevel')
import Plugin.Pl.Optimize (optimize)
import Plugin.Pl.Parser (parsePF)
import Plugin.Pl.PrettyPrinter (prettyTopLevel)
import Plugin.Pl.Transform (transform)
import Data.Maybe (listToMaybe)
{- |
>>> pointfree "I'm not a valid Haskell expression!"
[]
>>> pointfree "sum xs = foldr (+) 0 xs"
["sum = id (fix (const (foldr (+) 0)))","sum = fix (const (foldr (+) 0))","sum = foldr (+) 0"]
-}
pointfree :: String -> [String]
pointfree
= either
(const [])
(map prettyTopLevel . mapTopLevel' optimize . mapTopLevel transform)
. parsePF
{- |
>>> pointfree' "I'm not a valid Haskell expression!"
Nothing
>>> pointfree' "sum xs = foldr (+) 0 xs"
Just "sum = foldr (+) 0"
-}
pointfree' :: String -> Maybe String
pointfree' = listToMaybe . reverse . pointfree