How to add type annotation in let binding

前端 未结 3 755
陌清茗
陌清茗 2021-02-01 04:14

I\'m a beginner(ish) in Haskell and I find error message really hard to understand (I guess it comes with time). Anyway, to help me understanding my mistakes, I tried to add int

3条回答
  •  广开言路
    2021-02-01 04:44

    This should work:

    f :: s -> s
    f x =
       let y = undefined :: s
       in  y
    

    Just use the normal :: operator as shown in the above example for type annotation.

    Update:

    It doesn't seem to work with polymorphic types. But it works with an concrete type.

    The following typechecks:

    f :: Int -> Int
    f x = let m = x :: Int
          in m
    

    This produces error:

    f1 :: a -> a
    f1 x = let m = x :: a
           in m
    

提交回复
热议问题