[Haskell-beginners] why does the superclass not work?
Mihai Maruseac
mihai.maruseac at gmail.com
Wed Apr 29 20:11:54 UTC 2020
Hi.
Num is not a superclass of Int. Int is a type whereas Num is a type of a type.
The fix would be
sigmund :: Num a => a -> a
...
This signature means "sigmund has type a to a where a is constrained
to be a type variable of type Num" (so Num is the type of the type
variable a)
On Wed, Apr 29, 2020 at 12:41 PM Alexander Chen <alexander at chenjia.nl> wrote:
>
> Hi,
>
> superclass.hs
>
> myX = 1 :: Int
>
> sigmund :: Int -> Int
> sigmund x = myX
>
>
> prelude> :l superclass.hs
> [1 of 1] Compiling Main
> Ok, one module loaded.
>
> ==================================================================================
>
> superclass.hs
>
> myX = 1 :: Int
>
> sigmund :: Num -> Num
> sigmund x = myX
>
> prelude> :l superclass.hs
> typed_checked.hs:3:13: error:
> • Expecting one more argument to ‘Num’
> Expected a type, but ‘Num’ has kind ‘* -> Constraint’
> • In the type signature: sigmund :: Num -> Num
> |
> 3 | sigmund :: Num -> Num | ^^^
>
> typed_checked.hs:3:20: error:
> • Expecting one more argument to ‘Num’
> Expected a type, but ‘Num’ has kind ‘* -> Constraint’
> • In the type signature: sigmund :: Num -> Num
>
>
> ===================================================================================
>
> I would think since Num is a superclass of Int defining the type in the superclass would be OK, also in the error message it refers to (see black) what does that refer to?
>
> thanks!
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
--
Mihai Maruseac (MM)
"If you can't solve a problem, then there's an easier problem you can
solve: find it." -- George Polya
More information about the Beginners
mailing list