BullyWiiPlaza
BullyWiiPlaza

Reputation: 19185

Cons Data Type Outside Recursion

I'm trying to write a function which recursively goes through a data structure which internally uses a list once without modifying it. I'm having trouble prepending the element again outside of the recursion so that it won't dead loop.

difference (Set ((element, count) : set)) (MultiSet set')
    | ... = difference (Set ((element, count) : set)) (Set set') -- Prepends tuple inside the recursion
    | ...

What I need is a way of prepending the tuple (element, count) in front of the set without including it in the recursive call from difference.

What's an easy/standard way of doing this?

Upvotes: 0

Views: 92

Answers (1)

MathematicalOrchid
MathematicalOrchid

Reputation: 62818

It looks like what you might be looking for is

| ... = Set ((element, count) : difference set (Set set'))

No? How about this:

| ... = let Set set2 = difference set (Set set') in Set ((element, count) : set2)

(I'm assuming that Set is just data Set x = Set [x].)

Upvotes: 1

Related Questions