Sunday 15 September 2013

functional programming - How to make Haskell compute the correct polymorphic type? -


I realized how small-function might be useful.

Ex:

<<> Commandbill Lang = sort by (compare `current`)

But unfortunately, Can be intuitive.

Definition

  f on `g = \ xy - & gt; F (g x) (g y)  

for an example

  (x = y)>  (Length x) == (length y)  

But there are different types in both!

In the first [a] - & gt; [A] - & gt; Boole while in the second, the more common type of [a] - & gt; [B] - & gt; Bool .

It clearly denies the length of the correct word like (but (==)) [1, 2, 3] ["one", "b", "c"] (which should generate true , but still fails to type-checking).

I know that this restriction comes because of the use, but how far is it? Can someone design an implementation on , which can deal with polymorphic works (using universal quantification / rank-N types) correctly?

  {- # LANGUAGE rank 2 type # -} at ':: (a - & Gt; a - & gt; b) - & gt; (Forall DCD -> A) -> Ce -> Cf -> Fgxy = f (gx) on B Gy)  

The result of

 prelude> : at t '(==)  at (==) :: ( Eq a) => (Forall DCD -> A) -> CE -> CF -> Bull Prelude> : On T (==) Length: [E] -> gt; [F] -> On the other side, this signature also invalidates the  flag 'id , which is invalid Something less than desirable. 


  {- # LANGUAGE TemplateHaskell # -} Import Haskell.TH onE fg = dox & lt; - The new name "x" y & lt; - The new name "y" lamE [varP x, varP y] $ f 'appE` (g' api 'x) `Ape '(G`APE' veerie Y)  
: Set -xtemplateHaskell prelude> $ (on | [| (==) |] [| length] ] [1,2,3] ["A", "B", "C"] True Prelude> $ (OnE [| (==) |] [| Id |]) 4 5 false 

No comments:

Post a Comment