How to provide explicit type declarations for functions when using GHCi?

后端 未结 3 1693
轻奢々
轻奢々 2020-12-23 16:03

How to I define the equivalent of this function (taken from learnyouahaskell) inside GHCi?

import Data.List  

numUniques :: (Eq a) => [a] -> Int  
num         


        
3条回答
  •  礼貌的吻别
    2020-12-23 16:32

    Is there a way provide type declarations in GHCi?

    let numUniques' :: (Eq a) => [a] -> Int; numUniques' = length . nub
    

    Or is there another way to define functions like these which doesn't require type declarations?

    If you turn off the monomorphism restriction with -XNoMonomorphismRestriction, it will infer the right type.

提交回复
热议问题