Skip to content

Instantly share code, notes, and snippets.

@mxswd
Created December 30, 2013 00:33
Show Gist options
  • Save mxswd/8176449 to your computer and use it in GitHub Desktop.
Save mxswd/8176449 to your computer and use it in GitHub Desktop.
{-# 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