[Haskell-beginners] How to correctly define data types?
Davi Santos
dps.abc at gmail.com
Tue Jul 19 18:46:19 CEST 2011
Brent, thanks for answering.
Sorry, by "set" I meant "access" [the field "attributes"]. But you already
answered, it depends on the ML module implementation choice.
One more question about elegance:
How to make Examples "sortable" by distance to a reference point
"referenceEx"?
For instance, if referenceEx was not needed:
-----------------------------
listExs = [Example {att=[2,5,3]}, Example {att=[0,2,3]}, Example
{att=[2,0,9]}]
sortedExamples =
sort listExs
==================
With referenceEx, I tried this, but it is getting ugly:
------------------------------
sortedExamples =
sort $ map (ExamplesPair referenceEx) listExs
================
------ML.hs------------------------------------------
data ExamplesPairClass =
ExamplesPair {ex1 :: Example, ex2 :: Example} deriving (Show, Eq)
instance Ord ExamplesPairClass where
(ExamplesPair ex1 referenceEx) ≤ (ExamplesPair ex2 referenceEx) =
(ex1 distance referenceEx) ≤ (ex2 distance referenceEx)
==================================
Sorry that amount of code, it is terrible to read with no colorizing.
Davi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110719/02d7c384/attachment.htm>
More information about the Beginners
mailing list