Re: [Haskell-cafe] Re: Functional dependencies and Peano numbers (and hoogle-bug?)

Thanks for the great feedback. The bijective example was especially interesting. While reading "Fun with Type Functions" I notices GNum as an interesting alternative to the Num type class but I couldn't find any such package on hackagedb. Do anyone know if there is anything like GNum on hackagedb? On an unrelated note: I hoogled "to" (i.e. http://haskell.org/hoogle/?hoogle=to) and just got a blank page. Nothing. Nil (not even <html>...</html>). Is this a bug or a "feature"? :) The reason I hoogled it was because I'm searching for something like explicit casting found in many other languages, something similar to
class To f t where to :: f -> t
instance To a a where to x = x
instance (Real a, Fractional b) => To a b where to = realToFrac
instance (Read a) => To String (Maybe a) where to = maybeRead -- not from cgi :)
so I can write something like
("23.2" `to`) :: Maybe Double
or
((42 :: Integer) `to`) :: Float
Anyone made a module/package that solves this problem already? I cannot be the first that needs generic type safe conversion... . -- Oscar

Oscar Finnsson wrote:
Anyone made a module/package that solves this problem already? I cannot be the first that needs generic type safe conversion... .
There's a restricted version in logfloat:Data.Numer.RealToFrac[1] which generalizes the Prelude's realToFrac to improve performance and correctness. To do much more than that you'll probably have to use something like Data.Data, Data.Typeable, or similar. Generally speaking, arbitrary casts from one type to another go against Haskell ideology because they don't make a lot of sense. Often times there are multiple intelligible ways to convert between two fixed types, so how can we choose? Things like realToFrac, read, show, etc make sense precisely because they are more restricted and therefore make explicit the semantic intentions of how the conversion should be done. [1] http://hackage.haskell.org/packages/archive/logfloat/0.12.1/doc/html/Data-Nu... -- Live well, ~wren

Hi Oscar, Sorry for the seriously late reply. I only just found this message in the bottom of my inbox:
On an unrelated note:
I hoogled "to" (i.e. http://haskell.org/hoogle/?hoogle=to) and just got a blank page. Nothing. Nil (not even <html>...</html>). Is this a bug or a "feature"? :)
It was a bug, fixed in hoogle-4.2.1. I had an incomplete pattern match on "to", which crashed Hoogle. The reason "to" is treated specially is that when people search for "a to b", they usually mean "a -> b", and my code to detect this was incorrect. All fixed now. Thanks for the report. In future, if you find a bug in Hoogle can you please email me directly, or raise it on my bug tracker: http://code.google.com/p/ndmitchell/issues/ Thanks, Neil
participants (3)
-
Neil Mitchell
-
Oscar Finnsson
-
wren ng thornton