[Haskell-cafe] Defining types (newbie)
Bryan O'Sullivan
bos at serpentine.com
Tue Mar 13 23:20:42 EDT 2007
John Fouhy wrote:
> In Haskell, I envisage writing something like:
>
> data ThingCompare = TC Op Field
This wants to be a bit more concrete:
data ThingCompare = TC (a -> a -> Bool) (Thing -> a)
so that you could then have something to execute your comparison thingy:
runTC :: ThingCompare -> Thing -> Thing -> Bool
runTC (TC compare extract) a b = compare (extract a) (extract b)
and construct a value of it:
tcEqFirst = TC (==) first_field
so to compare two Things, you'd do something like this:
runTC tcEqFirst a b
<b
More information about the Haskell-Cafe
mailing list