Ошибка REPL при изменении аргументов записи - PullRequest
1 голос
/ 06 октября 2019

Рассмотрим shell :: String -> CreateProcess. Например:

Prelude System.IO System.Process> shell "pwd"
CreateProcess {cmdspec = ShellCommand "pwd", cwd = Nothing, env = Nothing, std_in = Inherit, std_out = Inherit, std_err = Inherit, close_fds = False, create_group = False, delegate_ctlc = False, detach_console = False, create_new_console = False, new_session = False, child_group = Nothing, child_user = Nothing, use_process_jobs = False}

Я пытаюсь изменить аргументы записи CreateProcess, но получаю сообщение об ошибке REPL:

Prelude System.IO System.Process> shell "pwd" { cwd = "/home" }

<interactive>:7:7: error:
    • Couldn't match type ‘CreateProcess’ with ‘[Char]’
      Expected type: String
        Actual type: CreateProcess
    • In the first argument of ‘shell’, namely ‘"pwd" {cwd = "/home"}’
      In the expression: shell "pwd" {cwd = "/home"}
      In an equation for ‘it’: it = shell "pwd" {cwd = "/home"}

<interactive>:7:21: error:
    • Couldn't match expected type ‘Maybe FilePath’
                  with actual type ‘[Char]’
    • In the ‘cwd’ field of a record
      In the first argument of ‘shell’, namely ‘"pwd" {cwd = "/home"}’
      In the expression: shell "pwd" {cwd = "/home"}

1 Ответ

3 голосов
/ 06 октября 2019

В вашем коде две проблемы.

  1. cwd имеет тип Maybe String, а не просто String, вам нужно явно использовать конструктор Just.
  2. По умолчанию {} привязаны к ближайшему аргументу, в данном случае это строка "cwd". Тем не менее, вы хотите указать поле результата вызова функции.

Написание вашего кода, как это работает для меня:

ghci> (shell "cwd") { cwd = Just "/home" }
CreateProcess 
    { cmdspec = ShellCommand "cwd" 
    , cwd = Just "/home" 
    , env = Nothing
    , std_in = Inherit
    , std_out = Inherit
    , std_err = Inherit
    , close_fds = False
    , create_group = False
    , delegate_ctlc = False
    , detach_console = False
    , create_new_console = False
    , new_session = False
    , child_group = Nothing
    , child_user = Nothing
    , use_process_jobs = False
    } 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...