[Haskell-beginners] Improve my lambda expressions
PATRICK BROWNE
patrick.browne at dit.ie
Mon Jun 26 09:38:10 UTC 2017
The code below provides a distance function that works for points and
moving point.
I am happy with the result, but I have a problem with the lambda
expressions.
Instead of supplying an argument to each 'mpXX', is it possible to have a
single lambda argument on the entire final 'md' function? (e.g. 'md 2')
Thanks in advance,
Pat
data Point a = Point { abscissa :: a, ordinate :: a } deriving Show
dist a b = sqrt (((abscissa a) - (abscissa b))^2 + ((ordinate a) -
(ordinate b))^2)
-- Sttic points
p1, p2 :: Point Float
p1 = Point 0.0 0.0
p2 = Point 4.0 4.0
d = dist p1 p2
-- Moving points
mp1, mp2 :: Point Float
mp1x = (\t -> 4.0 + 0.5 * t)
mp1y = (\t -> 4.0 - 0.5 * t)
mp1 = Point (mp1x 2) (mp1y 2)
mp2x = (\t -> 0.0 + 1.0 * t)
mp2y = (\t -> 0.0 - 1.0 * t)
mp2 = Point (mp2x 2) (mp2y 2)
md = dist mp1 mp2
--
This email originated from DIT. If you received this email in error, please
delete it from your system. Please note that if you are not the named
addressee, disclosing, copying, distributing or taking any action based on
the contents of this email or attachments is prohibited. www.dit.ie
Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí
earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an
seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon
dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa
ríomhphost nó sna hiatáin seo. www.dit.ie
Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to
Grangegorman <http://www.dit.ie/grangegorman>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20170626/c7fef45e/attachment.html>
More information about the Beginners
mailing list