Open Halvor0808 opened 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(?)
This can be done in 2 main ways.
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.
Currently
URI
andUrl
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.