Halvor0808 / gemini-webbrowser

GNU General Public License v3.0
0 stars 0 forks source link

Url datatype may be redundant #13

Open Halvor0808 opened 3 weeks ago

Halvor0808 commented 3 weeks ago

Currently URI and Url are handled through transformations between the two of them.

URI is from the Network.URI library. Url is from this project.

The Url datatype may be redundant. Investigate if this is true, and make changes accordingly.

Halvor0808 commented 3 weeks ago

Another consideration. When parsing for an absolute URI with parseAbsoluteURI from the Network.URI module, it provides no proper error message. Possibly rewrite the parsing to provide proper error messages for malformed URIs. Either Parsec/MegaParsec for proper errors(?)

Halvor0808 commented 1 week ago

Representation for URI and local pages

This can be done in 2 main ways.

  1. Algebraic data types
  2. Type class

Algebraic data types:

import Network.URI

data Url
  = NetworkURI URI
  | LocalPage LocalPageType

data LocalPageType
  = CustomHomePage
  | HelpScreen
  | OtherPageType1
  | OtherPageType2

This allows the code to be clear and easy to reason about. But changes may lead to changes in other files as well.

Type classes:

class UrlType a where
  getUrl :: a -> [Line]

data NetworkUrl = NetworkUrl URI

instance UrlType NetworkUrl where
  getUrl (NetworkUrl uri) = queryUri uri

data LocalPage = CustomHomePage | HelpScreen | OtherPageType1

instance UrlType LocalPage where
  -- custom behaviour
  getUrl CustomHomePage = -- "home" / start event
  getUrl HelpScreen = -- "help" / toggle help, etc.

Conclusion: leaning towards number 2. For the exercise and possibly good use, and furute extension.