Play function of Euterpea doesn't play notes?

72 views Asked by At

I am trying to make music using the Haskell Library Euterpea. I load a file which has line "import Euterpea" into ghci.

If I run something like,

play $ a 1 qn

Then succesfully it runs and a sound is played on my speaker. But, if I tell it run something like

play $ note (1/4) (A,4)

then it throws errors

<interactive>:6:1: error:
    * Couldn't match expected type: t0 -> (PitchClass, b0) -> t
                  with actual type: IO ()
    * The function `play' is applied to three value arguments,
        but its type `Music a1 -> IO ()' has only one
      In the expression: play note (1 / 4) (A, 4)
      In an equation for `it': it = play note (1 / 4) (A, 4)
    * Relevant bindings include it :: t (bound at <interactive>:6:1)

<interactive>:6:6: error:
    * Couldn't match expected type: Music a1
                  with actual type: Dur -> a0 -> Music a0
    * Probable cause: `note' is applied to too few arguments
      In the first argument of `play', namely `note'
      In the expression: play note (1 / 4) (A, 4)
      In an equation for `it': it = play note (1 / 4) (A, 4)

The above was supposed to, in the ideal case, play the quarter note of concert A (page-16 of Haskell School of Music)

Being unable to play this note expressions like this is stopping me from learning the book thoroughly. Could somone explain to my why it's not working.

1

There are 1 answers

0
tryst with freedom On

Found the answer myself. Just kept on reading, and this issue is tackled on page-37

Details: It is important when using play that the type of its argument is made clear. In the case of t251, it is clear from the type signature in its definition. But for reasons to be explained in Chapter 7, if we write even something very simple such as play (note qn (C,4)), Haskell cannot infer exactly what kind of number 4 is, and therefore cannot infer that (C,4) is intended to be a Pitch. We can get around this by writing:

 m :: Music Pitch 

 m = note qn (C,4) 

in which case play m will work just fine, or we can include the type signature “in-line” with the expression, as in play (note qn ((C,4) :: Pitch)).