Haskell没有Show的实例 [英] Haskell No instance for Show
问题描述
这是我的代码
类型Niveles =(Int,Int,Int)
type Persona =(String,Niveles)
type Pocion =(String,[(String,Int,[Efectos])])
类型Ingredientes = [(String,Int,[Efectos])]
type Efectos = Niveles - > Niveles
aplicar3 f(a,b,c)=(fa,fb,fc)
invertir3(a,b,c)=(c,b,a)
fst3(a,_,_)= a
snd3(_,b,_)= b
trd3(_,_,c)= c
personas = [(Harry,(11,5,4)),(Ron,(6,4,6)),(Hermione,(8,12,2)),( Draco,(7,9,6))]
f1(ns,nc,nf)=(ns + 1,nc + 2,nf + 3)
f2 = aplicar3 (最大7)
f3(ns,nc,nf)
| ns> = 8 =(ns,nc,nf + 5)
|否则=(ns,nc,nf-3)
misPociones :: [Pocion]
misPociones = [
(Felix Felices,[(Escarabajos Machacados,52 ,[f1,f2]),(Ojo de Tigre Sucio,2,[f3])]),
(Multijugos,[(Cuerno de Bicornio en Polvo,10,[invertir3,( (a,b,c)→(a,a,c))]),(Sanguijuela hormonal,54,[(aplicar3(* 2)),(\(a,b,c) - (a,c))])]),
(Flores de Bach,[(Orquidea Salvaje,8,[f3]),(Rosita,1,[f1 ])]]]]]]
efectosDePocion pocion = map trd3(elementos pocion)
elementos :: Pocion - >成分
元素(_,ingredientes)= ingredientes
最后一段代码,当我尝试使用函数elementos时:
$ b
elementos(Felix Felices,[ (Escarabajos Machacados,52,[f1,f2]),(Ojo de Tigre Sucio,2,[f3])])
< interactive>:311:1 :
由于使用`print'而产生的$(显示((Int,Int,Int) - >(Int,Int,Int)))
的实例
可能的修正:
为
添加实例声明(Show((Int,Int,Int) - >(Int,Int,Int)))
在一个交互式GHCi命令中:print it
有人可以向我解释吗?
将以下代码添加到.hs文件中
instance显示(a - &b; b)其中
显示a =funcion
现在ghci将能够打印funcion(函数)
祝你好运! p>
Here is my code
type Niveles = (Int, Int, Int)
type Persona = (String, Niveles)
type Pocion = (String, [(String, Int, [Efectos])])
type Ingredientes = [(String, Int, [Efectos])]
type Efectos = Niveles -> Niveles
aplicar3 f (a,b,c) = (f a, f b, f c)
invertir3 (a,b,c) = (c,b,a)
fst3 (a,_,_) = a
snd3 (_,b,_) = b
trd3 (_,_,c) = c
personas = [("Harry",(11, 5, 4)), ("Ron",(6,4,6)), ("Hermione",(8,12,2)), ("Draco",(7,9,6))]
f1 (ns,nc,nf) = (ns+1,nc+2,nf+3)
f2 = aplicar3 (max 7)
f3 (ns,nc,nf)
| ns >= 8 = (ns,nc,nf+5)
| otherwise = (ns,nc,nf-3)
misPociones :: [Pocion]
misPociones = [
("Felix Felices",[("Escarabajos Machacados",52,[f1,f2]),("Ojo de Tigre Sucio",2,[f3])]),
("Multijugos",[("Cuerno de Bicornio en Polvo",10, [invertir3, (\(a,b,c) -> (a,a,c))]),("Sanguijuela hormonal",54,[(aplicar3 (*2)), (\(a,b,c) -> (a,a,c)) ])]),
("Flores de Bach",[("Orquidea Salvaje",8,[f3]), ("Rosita",1,[f1])])]
efectosDePocion pocion = map trd3 (elementos pocion)
elementos :: Pocion -> Ingredientes
elementos (_, ingredientes) = ingredientes
I have a problem in the last piece of code, when I try to use the function "elementos":
elementos ("Felix Felices",[("Escarabajos Machacados",52,[f1,f2]),("Ojo de Tigre Sucio",2,[f3])])
I 've got an error message:
<interactive>:311:1:
No instance for (Show ((Int, Int, Int) -> (Int, Int, Int)))
arising from a use of `print'
Possible fix:
add an instance declaration for
(Show ((Int, Int, Int) -> (Int, Int, Int)))
In a stmt of an interactive GHCi command: print it
Can someone explain this to me? How can i fix it?
Add to your .hs file the following code
instance Show (a -> b) where
show a= "funcion"
Now ghci will be able to print "funcion" (function)
Good luck!
这篇关于Haskell没有Show的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!