Created
December 30, 2013 00:33
-
-
Save mxswd/8176449 to your computer and use it in GitHub Desktop.
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
{-# LANGUAGE TemplateHaskell #-} | |
module Rect (Rect, x, y, rect) where | |
import Control.Lens | |
import Data.Functor | |
data Rect = Rect { _x :: Int, _y :: Int } | |
makeLenses ''Rect | |
-- rect :: ... | |
rect f x y = Rect <$> (f x y) | |
-- example usage | |
square :: Int -> Rect | |
square x = create rect $ x x | |
abox :: Rect | |
abox = create rect $ 4 10 | |
describe :: Rect -> String | |
describe = [match| | |
rect 4 4 -> "square with sides of length 4" | |
rect x x -> "a square" | |
rect x y -> "a rectangle" | |
|] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment