Search Results

Search found 7 results on 1 pages for 'sisif'.

Page 1/1 | 1 

  • simple putStrLn in Haskell/Yampa with arrows syntax

    - by sisif
    i'm using Haskell with the Yampa FRP library which uses the arrows language extension. how can i do a simple putStrLn in a SF? mySF = proc x -> do y <- identity -< x*x putStrLn "Hello World!" ++ show y returnA -< y the arrow syntax complains about the expression not bein an arrow (of course), but even with arrows i get no output output <- identity -< putStrLn "Hello World!"

    Read the article

  • mapping list of different types implementing same function?

    - by sisif
    I want to apply a function to every element in a list (map) but the elements may have different types but all implement the same function (here "putOut") like an interface. However I cannot create a list of this "interface" type (here "Outputable"). How do I map a list of different types implementing the same function? main :: IO () main = do map putOut lst putStrLn "end" where lst :: [Outputable] -- ERROR: Class "Outputable" used as a type lst = [(Out1 1),(Out2 1 2)] class Outputable a where putOut :: a -> IO () -- user defined: data Out1 = Out1 Int deriving (Show) data Out2 = Out2 Int deriving (Show) instance Outputable Out1 where putOut out1 = putStrLn $ show out1 instance Outputable Out2 where putOut out2 = putStrLn $ show out2 I cannot define it this way: data Out = Out1 Int | Out2 Int Int putOut Out1 = ... putOut Out2 = ... because this is a library and users should be able to extend Out with their own types

    Read the article

  • Type signature "Maybe a" doesn't like "Just [Event]"

    - by sisif
    I'm still learning Haskell and need help with the type inference please! Using packages SDL and Yampa I get the following type signature from FRP.Yampa.reactimate: (Bool -> IO (DTime, Maybe a)) and I want to use it for: myInput :: Bool -> IO (DTime, Maybe [SDL.Event]) myInput isBlocking = do event <- SDL.pollEvent return (1, Just [event]) ... reactimate myInit myInput myOutput mySF but it says Couldn't match expected type `()' against inferred type `[SDL.Event]' Expected type: IO (DTime, Maybe ()) Inferred type: IO (DTime, Maybe [SDL.Event]) In the second argument of `reactimate', namely `input' In the expression: reactimate initialize input output process I thought Maybe a allows me to use anything, even a SDL.Event list? Why is it expecting Maybe () when the type signature is actually Maybe a? Why does it want an empty tuple, or a function taking no arguments, or what is () supposed to be?

    Read the article

  • (newbie) type signature "Maybe a" doesn't like "Just [Event]"

    - by sisif
    i'm still learning Haskell and need help with the type inference please! using packages SDL and Yampa i get the following type signature from FRP.Yampa.reactimate: (Bool -> IO (DTime, Maybe a)) and i want to use it for: myInput :: Bool -> IO (DTime, Maybe [SDL.Event]) myInput isBlocking = do event <- SDL.pollEvent return (1, Just [event]) ... reactimate myInit myInput myOutput mySF but it says Couldn't match expected type `()' against inferred type `[SDL.Event]' Expected type: IO (DTime, Maybe ()) Inferred type: IO (DTime, Maybe [SDL.Event]) In the second argument of `reactimate', namely `input' In the expression: reactimate initialize input output process i thought "Maybe a" allows me to use anything, even a SDL.Event list? why is it expecting "Maybe ()" when the type signature is actually "Maybe a"? why does it want an empty tuple, or a function taking no arguments, or what is () supposed to be?

    Read the article

  • Collecting IO outputs into list

    - by sisif
    how can i do multiple calls to SDL.pollEvent :: IO Event until the output is SDL.NoEvent and collect all the results into a list? in imperative terms something like this: events = [] event = SDL.pollEvent; while( event != SDL.NoEvent ) events.add( event ) event = SDL.pollEvent

    Read the article

1