[Haskell-cafe] Types of partially instantiated polymorphic helper functions
Tom Ellis
tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk
Tue Nov 24 22:37:40 UTC 2020
On Tue, Nov 24, 2020 at 02:26:03PM -0800, Todd Wilson wrote:
> This has got to be a trivial question, but I don't see a solution, nor
> could I find anything through searching: If I want to write a type
> declaration for the helper function g here, what do I write?
>
> f :: a -> [b] -> [(a,b)]
> f a bs = g bs where
> g :: ????
> g [] = []
> g (x:xs) = (a,x) : g xs
You probably want this:
{-# LANGUAGE ScopedTypeVariables #-}
f :: forall a b. a -> [b] -> [(a,b)]
f a bs = g bs where
g :: [b'] -> [(a, b')]
g [] = []
g (x:xs) = (a,x) : g xs
More information about the Haskell-Cafe
mailing list