You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Brick开发Haskell CLI时,Next与continue未导出问题

解决方案

这是Brick版本迭代导致的API变更:Brick 0.19及以后的版本重构了事件处理逻辑,移除了Next类型、continue和halt函数,改用更简洁的返回值范式:

  1. 调整类型签名
    原返回类型EventM n (Next AppState)替换为EventM n (Maybe AppState):

    • 返回Just newState:等价于旧版的continue newState,表示继续运行并更新应用状态
    • 返回Nothing:等价于旧版的halt state,表示终止应用
  2. 修改后的代码示例
    更新Main.hs的handleEvent函数:

    module Main where
    
    import Brick.Main
    import Brick.Types
    import Graphics.Vty.Input.Events
    
    data AppState = AppState deriving (Show, Eq)
    
    -- 更新类型签名为新的返回格式
    handleEvent :: AppState -> BrickEvent n e -> EventM n (Maybe AppState)
    handleEvent s e =
        case e of
            VtyEvent vtye ->
                case vtye of
                    EvKey (KChar 'q') [] -> pure Nothing  -- 终止应用
                    _ -> pure (Just s)                   -- 继续运行
            _ -> pure (Just s)
    
  3. 版本适配说明

    • 若你需要使用旧版Brick(0.18及更早),需确保从Brick.Main显式导入Next、continue、halt,但官方已不再维护旧版API
    • 建议升级到Brick最新稳定版,采用新的事件处理逻辑,官方文档和示例已同步更新至该范式

内容的提问来源于stack exchange,提问作者Alex Scriba

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 20:22:55