Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Improved handleArcs function. #51

Merged
merged 6 commits into from
Sep 17, 2016
Merged

Improved handleArcs function. #51

merged 6 commits into from
Sep 17, 2016

Conversation

jrbeaumont
Copy link
Member

Removed explicit recursion.

Added extra to the cabal file, required for groupSortOn.

jrbeaumont and others added 4 commits September 16, 2016 21:43
Copy link
Member

@snowleopard snowleopard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments on existing code:

  • I think boolBit is just standard fromEnum.
  • Shall we rename DynSignal to just Signal? I think it's clearer: data Signal = Signal Int deriving Eq.
  • This will break when there are more than 26 signals: show (Signal i) = [chr (ord 'A' + i)]. Think how to improve.
  • This is a bit sad: "+"isSuffixOff. Can't you convert to strings later, so you can avoid testing strings instead of working with Transition type?
  • In initVals, can't you replace foldr (\s -> (++)... simply with map?
  • Can you remove explicit recursion from arcPairs and initVal?
  • In output, use nubOrd from extra, which is faster.
  • Should symbLoop be called consistencyLoop as in the paper?

@@ -32,6 +33,12 @@ data DynSignal = Signal Int deriving Eq

instance Show DynSignal where show (Signal i) = [chr (ord 'A' + i)]

instance Ord DynSignal
where
(<=) (Signal x) (Signal y)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you prefer <= instead of compare you should at least simplify this as follows :-)

instance Ord DynSignal
    where
       Signal x <= Signal y = x <= y

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually just forgot to change this to compare, so I'm gonna use that. It just seems a little nicer to me for some reason

where
effect = snd (head arcLists)
causesForEffect = filter (\o -> snd o == effect) arcLists
causesLists = map fst causesForEffect
causesLists = map fst arcLists
mapped = sequence causesLists
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think name mapped is not very meaningful (maybe it used to, but lost the meaning after refactoring).

@@ -116,17 +123,13 @@ doTranslate signs circuit = do

-- TODO: 1) Get rid of explicit recursion (use groupBy)? 2) Improve performance.
Copy link
Member

@snowleopard snowleopard Sep 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can drop the TODO: there is no explicit recursion any more, and the code is faster (we do sorting + one pass, instead of multiple passes).

@jrbeaumont
Copy link
Member Author

Thanks for the comments, I will get to this ASAP.
It should be possible to do some work on most of these.

This will break when there are more than 26 signals: show (Signal i) = [chr (ord 'A' + i)]. Think how to improve.

I agree this needs improvement, but I don't believe it can be a quick fix, and it can be fixed with #35, allowing a user to define their own signal names.

@snowleopard
Copy link
Member

I agree this needs improvement, but I don't believe it can be a quick fix

Well, there are plenty of quick fixes! For example:

show (Signal i)
    | i < 26    = [chr (ord 'A' + i)]
    | otherwise = 'S' : show i

and it can be fixed with #35, allowing a user to define their own signal names.

True, that would be preferable.

@jrbeaumont
Copy link
Member Author

instance Show Signal where show (Signal i)
    | i < 26    = [chr (ord 'A' + i)]
    | otherwise = 'S' : show i

This throws errors, it doesn't like the |.
I'm gonna come back to this soon. 26 signals at this point is quite a lot, but it does need some adjustment.

@snowleopard
Copy link
Member

snowleopard commented Sep 17, 2016

I think formatting is wrong, perhaps this will work:

instance Show Signal where
    show (Signal i)
        | i < 26    = [chr (ord 'A' + i)]
        | otherwise = 'S' : show i

@jrbeaumont
Copy link
Member Author

That works, thanks.
Next issue:

This is a bit sad: "+"isSuffixOff. Can't you convert to strings later, so you can avoid testing strings instead of working with Transition type?

Because of the numbering of transitions (e.g c+/1), I can't change the first argument to transition, (String, String) to (Transition Signal, Transition Signal). I can change it to (Transition Signal, String) which would remove "+" isSuffixOf.

@jrbeaumont
Copy link
Member Author

Made these changes now. Let me know if there's more to be done :)

@snowleopard snowleopard merged commit 20b714c into tuura:master Sep 17, 2016
@snowleopard
Copy link
Member

Merged from 10,600m above.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants