Type of return in do block

后端 未结 3 1481
谎友^
谎友^ 2021-01-21 04:17

I am trying to understand Monads in Haskell and during my countless experiments with code I have encountered this thing:

f2 = do   
  return \"da\"
3条回答
  •  走了就别回头了
    2021-01-21 04:59

    This is known Monomorphism_restriction

    Use signatures

    f2 :: Monad m => m String
    f2 = do   
      return "da"
    

    or use language extension:

    {-# LANGUAGE NoMonomorphismRestriction #-}
    f2 = do   
      return "da"
    

    to get valid code

提交回复
热议问题