Tuesday 15 September 2015

haskell - Why is there no Show instance for functions? -



haskell - Why is there no Show instance for functions? -

just quick conceptual question, trying larn , understand haskell better.

i know show function used convert values strings, why can't function types used show?

prelude> (\x -> x*3) <interactive>:7:1: no instance (show (a0 -> a0)) arising utilize of `print' possible fix: add together instance declaration (show (a0 -> a0)) in stmt of interactive ghci command: print prelude>

it's not can't, there's not reason to.

but if you'd like, can:

prelude> :{ prelude| instance show (a -> b) prelude| show _ = "a function." prelude| :} prelude> print (\x -> x + 7) function. prelude> print (\a b c -> + b + c) function.

if you'd show textual representation of function, - can't that. unlike metaprogramming languages ruby, js, etc, haskell code little knowledge of own internals.

haskell

No comments:

Post a Comment