You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Type aliases of applied generics are opaque: type ReadOnlyFile = FileHandle<CanRead, CannotWrite> matches nothing #173
A type alias whose right-hand side is an applied generic is not expanded by the typechecker. It is treated as a distinct opaque type, so it fails to match even the identical type it aliases.
error: `readLine` expects argument 1 to be FileHandle<CanRead, A>, but got ReadOnlyFile
readLine : FileHandle<CanRead, A> -> String?
An alias to a non-generic type is transparent and works:
type FilePath = String
let showPath(p: FilePath) -> String = p.length.to(String) # fine
So the defect is specific to aliases of applied generic types: the alias records the name but never expands to FileHandle<CanRead, CannotWrite> during assignability checking.
Why it matters
FileHandle<R, W> typestate is implemented (docs/typestate-file-plan.md), and its whole ergonomic story depends on naming the common instantiations. Without alias expansion, every signature has to spell out both phantom parameters, and the readable names the design invites (ReadOnlyFile, WriteOnlyFile, ReadWriteFile) cannot be defined at all.
Activity
Make file type alias work, fixes #173