Undefined at the type level

前端 未结 2 1484
遥遥无期
遥遥无期 2021-02-07 00:41

Often when I\'m playing with Haskell code, I stub things out with a type annotation and undefined.

foo :: String -> Int
foo = undefined


        
相关标签:
2条回答
  • 2021-02-07 01:35

    This question was asked and answered a long time ago; best practices have evolved since.

    These days, instead of undefined, for stubbing out code you should be using typed holes, and their type-level analogue, partial type signatures.

    0 讨论(0)
  • 2021-02-07 01:36

    You can use EmptyDataDecls to stub out a type, and with KindSignatures you can give it a kind:

    {-# LANGUAGE EmptyDataDecls, KindSignatures #-}
    
    data Foo :: * -> *
    

    You can also stub out the Monad instance without warnings with this option to GHC.

    {-# OPTIONS_GHC -fno-warn-missing-methods #-}
    
    instance Monad Foo
    

    And then you don't need to leave any implementation for return and >>=.

    0 讨论(0)
提交回复
热议问题