Skip to content

Instantly share code, notes, and snippets.

Created October 1, 2016 06:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import Data.Exists (Exists, mkExists, runExists)
type Circle = {x:: Int, y:: Int, r:: Int}
type Rectangle = {x:: Int, y:: Int, w:: Int, h:: Int}
drawCircle :: Circle -> String
drawCircle c = "This is a circle!"
drawRectangle :: Rectangle -> String
drawRectangle r = "This is a rectangle!"
data Component o = Component {
data:: o,
draw:: o -> String
aCircle = Component {
data: {x: 100, y:100, r: 100},
draw: drawCircle
aRectangle = Component {
data: {x:100, y:100, w:100, h:100},
draw: drawRectangle
objects :: Array (Exists Component)
objects = [
mkExists aCircle,
mkExists aRectangle
drawObject :: (Exists Component) -> String
drawObject = runExists (\(Component c) -> c.draw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment