{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreiemipsy2owwnpcm7j5ogl5mgumn54c4n7tx5w2xxkmecltr2y7i4i",
    "uri": "at://did:plc:pi6woz4d47bkuws673w2il2r/app.bsky.feed.post/3mnttmgkcbla2"
  },
  "path": "/t/is-there-a-way-to-get-a-oschar-literal-more-conveniently-than-osp-head/14206#post_9",
  "publishedAt": "2026-06-09T07:48:36.000Z",
  "site": "https://discourse.haskell.org",
  "tags": [
    "UTF-8"
  ],
  "textContent": "Keep in mind that `OsChar` is actually more or less a byte in an **encoded byte sequence**. You could argue it should have been named `OsWord` to avoid confusion.\n\nThere are cases where extracting an OsChar and pattern matching on it makes sense, e.g. notably with the filepath separator `/`, because it is **encoding agnostic**. But in other cases you may get nonsensical results if you expect OsChar to correspond to unicode code points or graphemes even. On windows (UTF-16) you may hit a surrogate or on a utf-8 unix system you may hit a multi byte unicode sequence.\n\nUsing `unsafeFromChar :: Char -> OsChar` and then `pack :: [OsChar] -> OsString` essentially truncates your unicode to the extended ascii range. You could now treat it as valid **latin1** , but it’s unclear if that makes any sense.\n\nIf you need proper semantic search, you need to decode first (e.g. to String or Text) and decide what the source encoding is.\n\nThe filepath extension char is a bit on the fence here: posix standard doesn’t specify a byte for it, but I believe it’s more or less convention that `0x2E` (anywhere in a byte sequence) denotes a filepath extension.\n\nIf we look at UTF-8 then it becomes apparent that we can’t accidentally have `0x2E` in a multibyte unicode sequence. All bytes in a multibyte unicode sequence always start in the range greater than `0x80` (so above the ascii range). That’s why the encoding is ascii compatible. You can’t get an accidental `/` or `.`.\n\nI don’t think that holds for all encodings, but the OS API won’t really care whether your string has a funny encoding. The filepath separator is a fixed byte.",
  "title": "Is there a way to get a OsChar literal more conveniently than osp + head"
}