Skip to content

Idea: OverloadedStrings and OverloadedLists for PortName? #707

Open
@dramforever

Description

@dramforever

Synthesize annotations are a bit annoying to read. The signal-to-noise ratio is pretty bad because most port names (like q or cin) are much shorter than PortName and PortProduct.

For example, this is from #654:

{-# ANN f
   (Synthesize
      { t_name   = "f"
      , t_inputs = [ PortName "a"
                   , PortProduct "" [ PortName "b", PortName "c" ] ]
      , t_output = PortProduct "res" [PortName "q"] }) #-}

But with -XOverloadedStrings and -XOverloadedLists and some instances, PortName and PortProduct "" can be elided like this:

{-# ANN f
   (Synthesize
      { t_name   = "f"
      , t_inputs = [ "a", [ "b", "c" ] ]
      , t_output = PortProduct "res" [ "q" ] }) #-}

The instances look like this:

import GHC.Exts

instance IsString PortName where
    fromString = PortName

instance IsList PortName where
    type Item PortName = PortName

    fromList = PortProduct ""

    toList = error "toList for PortName is not implemented"

Pros:

  • Shorter annotation is both easier to read and easier to write
  • Easy implementation
  • Backwards compatible AFAIK, and can mix with other PortNames (see PortProduct "res" [ ... ] above)

Cons:

  • Can be confusing for someone not familiar with what's going on
  • Two ways to write the same thing. Which one for documentation and tutorial?
  • toList always errors. Maybe we can only have IsString and only avoid typing out PortName for every port?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions