<div dir="ltr">yes you can, it's actually better to encapsulate all "lambdas" and intermediate values inside one function, provided you never use them anywhere else.<div>i advise using "where" as such:<div><br></div><div><font face="monospace, monospace">md n = dist (Point (fx n) (fy n)) (Point (gx n) (gy n))</font></div><div><font face="monospace, monospace"> where fx n = <span style="font-size:12.8px">4.0 + 0.5 * n</span></font></div><div><span style="font-size:12.8px"><font face="monospace, monospace"> fy n = </font></span><span style="font-family:monospace,monospace;font-size:12.8px">4.0 - 0.5 * n</span></div><div><span style="font-family:monospace,monospace;font-size:12.8px"> gx n = n * 1.0</span></div><div><span style="font-family:monospace,monospace;font-size:12.8px"> gy n = n * (-1.0)</span></div><div><span style="font-family:monospace,monospace;font-size:12.8px">-- then you can call "foo = md 2"</span></div><div><span style="font-size:12.8px"><font face="arial, helvetica, sans-serif"><br></font></span></div><div><span style="font-size:12.8px"><font face="arial, helvetica, sans-serif">it's more idiomatic to use where, i believe. however you can also choose to define the helpers before the expression defining the function, using "let ... in" like that:</font></span></div><div><span style="font-size:12.8px"><font face="arial, helvetica, sans-serif"><br></font></span></div><div><div><font face="monospace, monospace">md n = </font><span style="font-family:monospace,monospace">let </span><span style="font-family:monospace,monospace">fx n = </span><span style="font-family:monospace,monospace;font-size:12.8px">4.0 + 0.5 * n</span></div><div><span style="font-size:12.8px"><font face="monospace, monospace"> fy n = </font></span><span style="font-family:monospace,monospace;font-size:12.8px">4.0 - 0.5 * n</span></div><div><span style="font-family:monospace,monospace;font-size:12.8px"> gx n = n * 1.0</span></div><div><span style="font-family:monospace,monospace;font-size:12.8px"> gy n = n * (-1.0)</span></div></div><div><span style="font-family:monospace,monospace;font-size:12.8px"> in </span><span style="font-family:monospace,monospace">dist (Point (fx n) (fy n)) (Point (gx n) (gy n))</span></div><div><span style="font-family:monospace,monospace"><br></span></div><div><font face="arial, helvetica, sans-serif">be careful about the alignment. both ways are (in this example) strictly equivalent, it all depends on circumstances and taste.</font></div><div><font face="arial, helvetica, sans-serif"><br></font></div><div><font face="arial, helvetica, sans-serif">mind you if you don't want a function to be reused, merely one single value foo = md 2, you can always just write directly:</font></div><div><font face="monospace, monospace">foo = </font><span style="font-family:monospace,monospace">dist (Point (fx 2) (fy 2)) (Point (gx 2) (gy 2))</span></div><div><font face="monospace, monospace"> where fx n = <span style="font-size:12.8px">4.0 + 0.5 * n</span></font></div><div><span style="font-size:12.8px"><font face="monospace, monospace"> fy n = </font></span><span style="font-family:monospace,monospace;font-size:12.8px">4.0 - 0.5 * n</span></div><div><span style="font-family:monospace,monospace;font-size:12.8px"> gx n = n * 1.0</span></div><div><span style="font-family:monospace,monospace;font-size:12.8px"> gy n = n * (-1.0)</span></div><div class="gmail_extra"><br><div class="gmail_quote">2017-06-26 11:38 GMT+02:00 PATRICK BROWNE <span dir="ltr"><<a href="mailto:patrick.browne@dit.ie" target="_blank">patrick.browne@dit.ie</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>The code below provides a distance function that works for points and moving point.</div><div>I am happy with the result, but I have a problem with the lambda expressions.</div><div>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')</div><div>Thanks in advance,</div><div>Pat</div><div><br></div><div><div>data Point a = Point { abscissa :: a, ordinate :: a } deriving Show</div><div>dist a b = sqrt (((abscissa a) - (abscissa b))^2 + ((ordinate a) - (ordinate b))^2)</div><div><br></div><div>-- Sttic points</div><div>p1, p2 :: Point Float</div><div>p1 = Point 0.0 0.0</div><div>p2 = Point 4.0 4.0</div><div>d = dist p1 p2</div><div><br></div><div><br></div><div>-- Moving points</div><div>mp1, mp2 :: Point Float</div><div>mp1x = (\t -> 4.0 + 0.5 * t)</div><div>mp1y = (\t -> 4.0 - 0.5 * t)</div><div>mp1 = Point (mp1x 2) (mp1y 2)</div><div>mp2x = (\t -> 0.0 + 1.0 * t)</div><div>mp2y = (\t -> 0.0 - 1.0 * t)</div><div>mp2 = Point (mp2x 2) (mp2y 2)</div><div>md = dist mp1 mp2</div></div></div>
<br>
<p><span lang="EN-GB"><font size="2">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. <a href="http://www.dit.ie/" target="_blank">www.dit.ie</a></font></span></p><p><font size="2">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. <a href="http://www.dit.ie/" target="_blank">www.dit.ie</a></font></p><p><a href="http://www.dit.ie/grangegorman" target="_blank"><font size="2">Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to Grangegorman</font></a></p><br>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bi<wbr>n/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div></div></div>