Si quiero declarar una newtype
tal que tipo de tipo de valor está limitado a tener una instancia para una clase de tipo, parece como si pudiera hacer eso con:newtype con RankNTypes
{-# LANGUAGE RankNTypes #-}
newtype ShowBox = ShowBox (forall a. Show a => a)
compila GHC que muy bien, pero cuando intento y, de hecho utilizo ShowBox
con
ShowBox "hello"
consigo un error del compilador
<interactive>:1:18:
Could not deduce (a ~ [Char])
from the context (Show a)
bound by a type expected by the context: Show a => a
at <interactive>:1:10-24
`a' is a rigid type variable bound by
a type expected by the context: Show a => a at <interactive>:1:10
In the first argument of `ShowBox', namely `"hello"'
In the expression: ShowBox "hello"
In an equation for `a': a = ShowBox "hello"
¿Hay alguna manera de hacer que esto funcione?
¿Significa esta cuantificación lo que usted piensa que significa? Realmente no estoy seguro, yo mismo. Estoy pensando que _may_ significa que 'ShowBox' solo se puede aplicar a valores que son precisamente del tipo' Show a => a'. Estoy bastante interesado en ver cuál es la respuesta a esta pregunta. –