[GHC] #12708: RFC: Representation polymorphic Num
GHC
ghc-devs at haskell.org
Sun Nov 20 20:26:23 UTC 2016
#12708: RFC: Representation polymorphic Num
-------------------------------------+-------------------------------------
Reporter: Iceland_jack | Owner:
Type: feature request | Status: new
Priority: normal | Milestone:
Component: Core Libraries | Version: 8.0.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Iceland_jack):
Using the generalized function composition from the paper
{{{#!hs
(·) :: forall (r :: RuntimeRep) (a :: Type) (b :: Type) (c :: TYPE r).
(b -> c)
-> (a -> b)
-> (a -> c)
(f · g) x = f (g x)
}}}
we can write
{{{#!hs
fromInteger :: Integer -> Int#
fromInteger (fromInteger -> I# i) = i
fromInteger :: Integer -> Int#
fromInteger (fromInteger -> D# d) = d)
}}}
pointfree
{{{#!hs
fromInteger :: Integer -> Int#
fromInteger = getInt# · fromInteger where
getInt# :: Int -> Int#
getInt# (I# i) = i
fromInteger :: Integer -> Double#
fromInteger = getDouble# · fromInteger where
getDouble# :: Double -> Double#
getDouble# (D# d) = d
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12708#comment:19>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list