Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Nested where to unpack datastructure

19 views
Skip to first unread message

snth...@gmail.com

unread,
Jan 24, 2016, 11:59:12 AM1/24/16
to
I just started with Haskell and wanted to re-use a function from an existing library such that it maps onto my own funtion/datatype.

In order to make the function work, I need to unpack the given 'Line' datatype such that it maps to the 'type (Float, Float)' parameters that the library uses.

I started like this:

module Main (
main
) where

import Graphics.Gloss.Geometry.Line (intersectLineLine)

data Point = Point Float Float deriving (Show)
data Line = Line Point Point
data Circle = Circle Point Double
data Length = Length Double
data Object = PointObject Point | LineObject Line | CircleObject Circle | LengthObject Length
data Vector = Vector [Object]

lineLineXn :: Line -> Line -> Maybe Point
lineLineXn l1 l2 = intersectLineLine (p1x, p1y) (p2x, p2y) (p3x, p3y) (p4x, p4y)
where (p1x, p1y) = p1
where (p1, p2) = l1

main = return (lineLineXn (Line (0 0) (1 1)) (Line (0 0) (1 1)))


But that didn't work. Any suggestions?
0 new messages