11
votes

Is it possible to disable or work around the type system in Haskell? There are situations where it is convenient to have everything untyped as in Forth and BCPL or monotyped as in Mathematica. I'm thinking along the lines of declaring everything as the same type or of disabling type checking altogether.

Edit: In conformance with SO principles, this is a narrow technical question, not a request for discussion of the relative merits of different programming approaches. To rephrase the question, "Can Haskell be used in a way such that avoidance of type conflicts is entirely the responsibility of the programmer?"

3
Convenient, perhaps. But note that whatever solution you use will not be culturally idiomatic Haskell, which is always strongly typed. I suggest you leave your "inconveniences" behind and learn it the culturally normative way -- once you have spent some time with it, it will all fall into place and you will wonder why you thought you needed to disable the type checker. - luqui
+1 for use of "culturally normative" in answering a programming question. - Chris Taylor
apt-get install racket - sclv
@user287424 You will have to work harder to convince the folks here that "There are situations where it is convenient to have everything untyped". If you provide an example of such a situation, you may get more constructive answers that you can learn from. To your question: just store all your data as String and enjoy. - jberryman

3 Answers

8
votes

Also look at Data.Dynamic which allows you to have dynamically typed values in parts of your code without disabling type-checking throughout.

8
votes

GHC 7.6 (not released yet) has a similar feature, -fdefer-type-errors:

http://hackage.haskell.org/trac/ghc/wiki/DeferErrorsToRuntime

It will defer all type errors until runtime. It's not really untyped but it allows almost as much freedom.

7
votes

Even with fdefer-type-errors one wouldn't be avoiding the type system. Nor does it really allow type independence. The point of the flag is to allow code with type errors to compile, so long as the errors are not called by the Main function. In particular, any code with a type error, when actually called by a Haskell interpreter, will still fail.

While the prospect of untyped functions in Haskell might be tempting, it's worth noting that the type system is really at the heart of the language. The code proves its own functionality in compilation, and the rigidity of the type system prevents a large number of errors.

Perhaps if you gave a specific example of the problem you're having, the community could address it. Interconverting between number types is something that I've asked about before, and there are a number of good tricks.