Skip to content

Algorithm newtype introduced in createHash for better type safety#16

Open
m-rinaldi wants to merge 1 commit into
oreshinya:masterfrom
m-rinaldi:master
Open

Algorithm newtype introduced in createHash for better type safety#16
m-rinaldi wants to merge 1 commit into
oreshinya:masterfrom
m-rinaldi:master

Conversation

@m-rinaldi
Copy link
Copy Markdown

Changed the type of createHash from String -> Effect Hash to Algorithm -> Effect Hash.


So far, createHash has accepted a String representing the hash algorithm. This is ambiguous and error-prone — it gives no clue that the string represents the algorithm name, not the input to be hashed. This can easily lead to misuse or confusion, for example:

createHash "hello" -- mistakenly hashing "hello" instead of selecting the algorithm

This example will compile, but crash at runtime with:

Uncaught Error: Digest method not supported

By introducing the Algorithm newtype:

createHash (Algorithm "hello") -- clearly wrong: "hello" is not a valid algorithm

We make incorrect usage visibly suspicious. The newtype acts as a clue, encouraging the user to pause and consider what this string actually represents. It clarifies intent and helps prevent real-world runtime errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant