type-errors-pretty

error improvement

Memo

  • User-defined type errors を利用しているみたい

  • 基本的にはただのラッパー

  • 型レベルのエラーメッセージを改善するために便利だけど、技術的に面白いポイントは無い

type MessageText (e1 :: k) (e2 :: k) (es :: [k]) =
       'Text "You require the following two effects from your computation:"
 ':$$: 'Text ""
 ':$$: 'Text "    '" ':<>: 'ShowType e1 ':<>: 'Text "' and '" ':<>: 'ShowType e2 ':<>: 'Text "'"
 ':$$: 'Text ""
 ':$$: 'Text "However, your monad is capable of performing only the following effects:"
 ':$$: 'Text ""
 ':$$: 'Text "    " ':<>: 'ShowType es

使い方

{-# LANGUAGE DataKinds            #-}
{-# LANGUAGE ExplicitNamespaces   #-}
{-# LANGUAGE PolyKinds            #-}
{-# LANGUAGE TypeOperators        #-}
{-# LANGUAGE UndecidableInstances #-}
import Type.Errors.Pretty (type (<>), type (%), TypeError)

type MessageText (e1 :: k) (e2 :: k) (es :: [k])
    = "You require the following two effects from your computation:"
    % ""
    % "    '" <> e1 <> "' and '" <> e2 <> "'"
    % ""
    % "However, your monad is capable of performing only the following effects:"
    % ""
    % "    " <> es

instance TypeError (MessageText Int Bool '[Maybe Int, [a]]) => Num [a]

リソース

Last updated