Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE ForeignFunctionInterface #-}
- import Foreign
- import Foreign.C.Types
- data Point =
- Point Float Float deriving (Show)
- data Circle =
- Circle Point Float deriving (Show)
- distance :: Point -> Point -> Float
- distance (Point x1 y1) (Point x2 y2) =
- sqrt $ (abs $ x1 - x2) + (abs $ y1 - y2)
- intersect :: Circle -> Circle -> Bool
- intersect (Circle p1 r1) (Circle p2 r2) =
- distance p1 p2 <= r1 + r2
- area :: Circle -> Float
- area (Circle _ r) = r * r * 2 * pi
- data Option
- = PosixSyntax
- | LongestMatch
- | LogError
- | Literal
- | NeverNl
- | DotNl
- | NeverCapture
- | CaseSensitive
- | PerlCases
- | WordBoundary
- | OneLine
- deriving (Show)
- data Re = Re
- { regex :: [Char]
- , options :: [(Option, Bool)]
- } deriving (Show)
- defaultOptions =
- [ (PosixSyntax, False)
- , (LongestMatch, False)
- , (LogError, False)
- , (Literal, False)
- , (NeverNl, False)
- , (DotNl, False)
- , (NeverCapture, False)
- , (CaseSensitive, False)
- , (PerlCases, False)
- , (WordBoundary, False)
- , (OneLine, False)
- ]
- makeRe :: [Char] -> Re
- makeRe x = Re { regex = x, options = defaultOptions }
- makeRe' :: [Char] -> [(Option, Bool)] -> Re
- makeRe' x o = Re { regex = x, options = o }
- main :: IO()
- main = do
- putStrLn $ show $ distance (Point 0 0) (Point 1 1)
- putStrLn $ show $ (Point 10 5)
- putStrLn $ show $
- intersect (Circle (Point 1 1) 1)
- (Circle (Point 5 5) 1)
- putStrLn $ show $ area (Circle (Point 0 0) 5)
- putStrLn $ show $ makeRe "Hello, World!"
- putStrLn $ show $ makeRe' "Hello, World" []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement