Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to use OSPath instead of FilePath #455

Open
cloudyluna opened this issue May 12, 2024 · 9 comments
Open

Migrate to use OSPath instead of FilePath #455

cloudyluna opened this issue May 12, 2024 · 9 comments

Comments

@cloudyluna
Copy link

Hello! Let me start by saying thanks for this great library. I learned a lot by using it so far as a Haskell beginner. 😃

Anyways, I noticed that filepath package recommends to use OSPath instead of FilePath.

Since I believe that turtle is largely being used as a shell scripting alternative (including in cross-platform manner) and which means, may involve a lot of file and directory manipulations, I reckon it's probably better in long term to adopt OSPath?

I was inspired to open this issue after reading this post on Discourse.

Thanks!

@Gabriella439
Copy link
Owner

The main issue I see is that OsPath doesn't have an IsString instance. Other than that I'd be fine with migrating to it

@hasufell
Copy link

The main issue I see is that OsPath doesn't have an IsString instance. Other than that I'd be fine with migrating to it

It doesn't have one, because we can't write a sound instance.

@srghma
Copy link

srghma commented Aug 18, 2024

@hasufell
Copy link

hasufell commented Aug 19, 2024

maybe switch to https://hackage.haskell.org/package/path ?

#254 (comment)

It has the same issue and it's even worse, because you can have 4 different types:

  • Path Rel Dir
  • Path Abs Dir
  • Path Rel File
  • Path Abs File

Which one is it gonna be when you write "foo"? You could distinguish via trailing slash, but that's fairly finicky. I guess for turtle that could make sense... so just write an orphan instance.

Wrt OsPath the issue is more nuanced (note that path now also has an OsPath variant: https://hackage.haskell.org/package/path-0.9.6/docs/OsPath.html), because you have to assume an encoding. Again, doing that generically for IsString is just incredibly bad API, so we won't do that. For this library, it can make sense to assume utf-8/16. So again: an orphan instance seems fine. os-string/filepath won't add one, so you don't have to worry about that.

@srghma
Copy link

srghma commented Aug 20, 2024

I dont know why we need IsString at all

@Gabriella439
Copy link
Owner

One reason why I insist on an IsString instance is that turtle is supposed to be ergonomic to use from within a ghci REPL

@srghma
Copy link

srghma commented Aug 21, 2024

I think IsString is possible

Path Rel Dir - ./foo/
Path Abs Dir - /foo/
Path Rel File - ./foo.txt
Path Abs File - /foo.txt

@hasufell
Copy link

I think IsString is possible

Path Rel Dir - ./foo/
Path Abs Dir - /foo/
Path Rel File - ./foo.txt
Path Abs File - /foo.txt

You're aware parsing can fail, right? E.g. /foo/../bar is not permitted by the path library.

Since IsString can't express failure, what are you going to do?

@srghma
Copy link

srghma commented Aug 21, 2024

Right, I didnt think about it
@Gabriella439 maybe better use TemplateHaskell?

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

No branches or pull requests

4 participants