Show list of unknown type in Haskell -
i given assignment in should have type signature
group g => int -> int -> [[g]] however if g ambiguous how can print it? error:
no instance (show g0) arising use of ‘print’ type variable ‘g0’ ambiguous note: there several potential instances: instance show double -- defined in ‘ghc.float’ instance show float -- defined in ‘ghc.float’ instance (integral a, show a) => show (ghc.real.ratio a) -- defined in ‘ghc.real’ ...plus 24 others in expression: print in expression: print $ mytest 10 0 in equation ‘main’: main = print $ mytest 10 0 which makes sense me. there error in assignment? or there way print ambiguous type?
try running
> :info group this should print out group typeclass , members, followed list of instances. pick 1 of these instances, execute
> mytest 1 2 :: [[thetypeyoupicked]] if wanted use inside main you'll have give type signature there too:
main :: io () main = print (mytest 10 0 :: [[thetypeyoupicked]]) the reason why compiler showing error because there many instances of group choose from, not of them implement show well. in order print in console, either executing (there's implicit print when run normal function in ghci) or explicit print needs implement show.
Comments
Post a Comment