Discussion:
[elm-discuss] What heap implementations exist for Elm?
'Rupert Smith' via Elm Discuss
2017-05-17 10:40:35 UTC
Permalink
I need a heap where I can supply my own ordering function:

ordering : a -> a -> Order

And be able to take the smallest item from the heap:

Heap.least : Heap a -> a

There is this one:

http://package.elm-lang.org/packages/TSFoster/elm-heap/latest

Any others?
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Rupert Smith' via Elm Discuss
2017-05-17 14:57:43 UTC
Permalink
Post by 'Rupert Smith' via Elm Discuss
http://package.elm-lang.org/packages/TSFoster/elm-heap/latest
Bugger. This heap implementation does not allow and arbitrary comparison
function. It has this:

by : (a -> comparable) -> Options b -> Options a

But that requires a mapping from the type being compares onto comparable.

If there is an implementation that lets me use a comparison function of
type 'a -> a -> Order', that would be better.
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
'Rupert Smith' via Elm Discuss
2017-05-17 15:06:37 UTC
Permalink
Post by 'Rupert Smith' via Elm Discuss
Post by 'Rupert Smith' via Elm Discuss
http://package.elm-lang.org/packages/TSFoster/elm-heap/latest
Bugger. This heap implementation does not allow and arbitrary comparison
by : (a -> comparable) -> Options b -> Options a
But that requires a mapping from the type being compares onto comparable.
If there is an implementation that lets me use a comparison function of
type 'a -> a -> Order', that would be better.
But internally it does use an 'a -> a -> Order':

type Options a
= Options
{ order : SortOrder
, compare : a -> a -> Order
}

Which it builds by converting an 'a -> comparable' function:

makeCompare : (a -> comparable) -> (a -> a -> Order)
makeCompare fn a b =
Basics.compare (fn a) (fn b)

Perhaps the author meant to expose Options(..) so users can build their own
compare function?
--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...