I have been reading through a Haskell d3js library:
This is the code defining Haskell box:
box :: Selector -> (Double,Double) -> St (Var' Selection)
box parent (w,h) = do
assign
$ ((d3Root
>>> select parent
>>> func "append" [PText "svg"]
>>> width w
>>> height h
>>> style "background" "#eef") :: Chain () Selection)
The code actually exporting using the box
function in d3.js code uses the >>=
operator like this:
import Control.Monad
import qualified Data.Text as T
import D3JS
test :: Int -> IO ()
test n = T.writeFile "generated.js" $ reify (box "#div1" (300,300) >>= bars n 300 (Data1D [100,20,80,60,120]))
To avoid being like this unpopular question on arrows: How to use arrow operators in haskell Where can I find the type signatures, or other basic information? Are there resources where I can learn more about:
$
Haskell: difference between . (dot) and $ (dollar sign)>>>
this could be an arrow but I don't see where I imported it.>>=
The first one was easy to find but the answer was confusing:
*Main Lib> :t ($)
($) :: (a -> b) -> a -> b
I found that f $ a b c = f ( (a b) c )
while f a b c = (((f a) b) c
Prelude gives a similar response for >>=
involving monads. In my case, it might be the IO monad. Or the d3js statement monad St()
*Main Lib> :t (>>=)
(>>=) :: Monad m => m a -> (a -> m b) -> m b
The last one doesn't show up at all... which is too bad because it looks pretty essential
*Main Lib> :t (>>>)
<interactive>:1:1:
Not in scope: ‘>>>’
Perhaps you meant one of these:
‘>>’ (imported from Prelude), ‘>>=’ (imported from Prelude)
Lastly at the risk of bundling too many questions at once. Can someone explain this type signature? Especially the last item:
box :: Selector -> (Double,Double) -> St (Var' Selection)
>>>
is actually defined inControl.Category
now. (Category
is the superclass ofArrow
.) – chepner>>>
, you can add a "hole" at any point e.g. changex1 >>> x2 >>> x3
intox1 >>> _ >>> x2 >>> x3
. This will make GHC raise an error during compilation, carrying the type which should be used in the hole. You can look up that type on Hoogle, and see what>>>
is. (Ditto for>>=
, or many other things). – chi>>>
on Hoogle. Do you know which category might be used here? Does this arrow>>>
know that automatically? – john mangual