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

后端 未结 3 1713
轻奢々
轻奢々 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:40

    The GHC User's Guide shows two additional ways to achieve this. This subsection introduces the :{ ... :} construct, which can be used as follows:

    > :{
    | numUniques :: (Eq a) => [a] -> Int
    | numUniques = length . nub
    | :}
    

    Alternatively, you can enable multiline mode:

    > :set +m
    > let
    | numUniques :: (Eq a) => [a] -> Int
    | numUniques = length . nub
    | 
    

提交回复
热议问题