haskellnetwire

Build a (Wire s e m a c) from (a -> b -> c) and (Wire s e m a b)


As a simple example I have this.

import Prelude hiding ((.))
import FRP.Netwire
import Control.Wire

f :: Int -> Char -> String
f = replicate

w :: => Wire s e m Int Char
w = mkSF_ fromInt
    where
        fromInt :: Int -> Char
        fromInt 1 = 'a'
        fromInt 2 = 'b'
        fromInt _ = '_'

w2 :: Wire s e m Int String
w2 = undefined -- This is where I get stuck

And I would like to be able to create a wire from Int's to Strings.

I think it should be easy, but I'm having no luck.


Solution

  • Another option is to use applicative syntax, which is even cleaner, imo

    w2 :: Monad m => Wire s e m Int String
    w2 = f <$> id <*> w
    

    This generalizes to

    (Category cat, Applicative (cat a)) => (a -> b -> c) -> cat a b -> cat a c
    

    Note that every Arrow gives rise to the above constraint.