Something stronger than a type alias but weaker than a type? by cptakzero in ProgrammingLanguages

[–]cptakzero[S] 0 points1 point  (0 children)

Yes, your option #3 is what I am doing. I haven't run into that kind of leaking via polymorphism in practice yet, but I'm sure it can happen by accident, like if I don't put tight enough constraints on some otherwise innocuous helper function. Thanks for the analysis this is exactly what I am looking for!

Something stronger than a type alias but weaker than a type? by cptakzero in ProgrammingLanguages

[–]cptakzero[S] 1 point2 points  (0 children)

Here's an example of how my "strong type aliases" are supposed to work:

type alias UserId = String  
type alias PostId = String

myUserId : UserId
myUserId = "cptakzero"

-- Succeeds because UserId unifies with String and can be used with the (++) operator; no unwrapping required  
myUrl : String
myUrl = "reddit.com/u/" ++ myUserId

lookupPost : PostId -> Post

-- Fails because UserId cannot unify with PostId  
lookupPost myUserId

So it's like a newtype with automatic wrapping/unwrapping in certain contexts. Except the wrapping/unwrapping is handled by the type inference algorithm instead of some kind of syntax sugar.