mkStringExprFS str
  | nullFS str
  = return (mkNilExpr charTy)

  | all safeChar chars
  = do unpack_id <- lookupId unpackCStringName
       return (App (Var unpack_id) (Lit (MachStr (fastStringToByteString str))))

  | otherwise
  = do unpack_id <- lookupId unpackCStringUtf8Name
       return (App (Var unpack_id) (Lit (MachStr (fastStringToByteString str))))

  where
    chars = unpackFS str
    safeChar c = ord c >= 1 && ord c <= 0x7F

-- This take a ~# b (or a ~# R b) and returns a ~ b (or Coercible a b)
mkStringExprFS str
  | nullFS str
  = return (mkNilExpr charTy)

  | all safeChar chars
  = do unpack_id <- lookupId unpackCStringName
       return (App (Var unpack_id) (Lit (MachStr (fastStringToByteString str))))

  | otherwise
  = do unpack_id <- lookupId unpackCStringUtf8Name
       return (App (Var unpack_id) (Lit (MachStr (fastStringToByteString str))))

  where
    chars = unpackFS str
    safeChar c = ord c >= 1 && ord c <= 0x7F

-- This take a ~# b (or a ~# R b) and returns a ~ b (or Coercible a b)
mkStringExprFS str
  | nullFS str
  = return (mkNilExpr charTy)

  | all safeChar chars
  = do unpack_id <- lookupId unpackCStringName
       return (App (Var unpack_id) (Lit (MachStr (fastStringToByteString str))))

  | otherwise
  = do unpack_id <- lookupId unpackCStringUtf8Name
       return (App (Var unpack_id) (Lit (MachStr (fastStringToByteString str))))

  where
    chars = unpackFS str
    safeChar c = ord c >= 1 && ord c <= 0x7F

-- This take a ~# b (or a ~# R b) and returns a ~ b (or Coercible a b)