Skip to content

os-string as a typeclass? #12

@domenkozar

Description

@domenkozar

I've started writing a typeclass for all conversions:

class ToOS a b where
  toOS :: a -> b

instance ToOS ByteString OsString where
  toOS = OsString . toOS

instance ToOS PosixPath OsString where
  toOS = OsString 

instance ToOS ByteString PosixPath where
  toOS = coerce . BSS.toShort

instance ToOS PosixPath ByteString where
  toOS = BSS.fromShort . coerce

...

Then I've realized that some of the conversions would raise an exception like FilePath -> m PosixPath.

On top of that, a lot of these conversions are O(n) and now each library has to implement all the different interfaces.

Doesn't that smell like there should be a OsString typeclass for common operations just like we have Num?

class OsString a where
  pathSeparator :: a
  pathSeparators :: [a]
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions