Skip to content

Instantly share code, notes, and snippets.

@afcondon
Created October 2, 2016 11:14
Show Gist options
  • Save afcondon/c683df7933e97a642c246387a4af4b64 to your computer and use it in GitHub Desktop.
Save afcondon/c683df7933e97a642c246387a4af4b64 to your computer and use it in GitHub Desktop.
module Main where
import Prelude (Unit)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Data.Function.Eff (EffFn4, EffFn3, mkEffFn4, runEffFn3)
foreign import data D3 :: !
foreign import data Selection :: * -> *
foreign import data D3Element :: *
type PredicateFn d x = ∀ eff. (d -> Number -> (Array D3Element) -> D3Element -> Eff (d3::D3|eff) x)
data AttrSetter d x = SetAttr x
| AttrFn (PredicateFn d x) -- rename both data ctor and Type here TODO
foreign import attrFn :: ∀ d v eff. EffFn3 (d3::D3|eff) String v (Selection d) (Selection d)
foreign import attrFnP :: ∀ d x eff. EffFn3 (d3::D3|eff) -- eff of attrFnP
String -- 1st arg of attrFnP
(EffFn4 (d3::D3|eff) -- eff of callback (callback is 2nd arg of fn)
d -- 1st arg of callback
Number -- 2nd arg of callback
(Array D3Element) -- 3rd arg of callback
D3Element -- 4th arg of callback
x) -- result of callback, what the attr is to be set to
(Selection d) -- 3rd arg of attrFnP
(Selection d) -- result of attrFnP
attr :: ∀ d x eff. String -> AttrSetter d x -> Selection d -> Eff (d3::D3|eff) (Selection d)
attr s (SetAttr x) = runEffFn3 attrFn s x
attr s (AttrFn p) = runEffFn3 attrFnP s (mkEffFn4 p)
main :: forall e. Eff (console :: CONSOLE | e) Unit
main = do
log "Hello sailor!"
@afcondon
Copy link
Author

afcondon commented Oct 2, 2016

Very weird, code above compiles but in more meaty example line 32 (mkEffFn4 p) fails as follows:

117  attr s (AttrFn p)            = runEffFn3 attrFnP s (mkEffFn4 p)
                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  Could not match type

    d0

  with type

    x3

  while trying to match type Selection d0
    with type Selection t2
  while checking that expression ((runEffFn3 attrFnP) s) (mkEffFn4 p)
    has type Selection d0
             -> Eff
                  ( d3 :: D3
                  | eff1
                  )
                  (Selection d0)
  in value declaration attr

  where eff1 is a rigid type variable
          bound at line 116, column 1 - line 116, column 53
        x3 is a rigid type variable
          bound at line 116, column 1 - line 116, column 53
        d0 is a rigid type variable
          bound at line 116, column 1 - line 116, column 53
        t2 is an unknown type

Link to source line of that error in the purescript-d3v4 repo:
https://github.com/afcondon/purescript-d3v4/blob/newstart/src/Selection.purs#L117

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment