Q:

Self defined Function to replicate a Number and return a List?

 myreplica :: (Num a,Ord a) => a -> b -> [b]
 myreplica num val 
         | num <= 0 = []
         | otherwise = [val] ++ myreplica (num-1) val

The above function takes two values Num and Val and returns a List L = [val,val...num times].The code works fine for 0 and positive values but when i give input like 
"ghci> " replicate' -1 123 

<interactive>:72:1:
    Non type-variable argument in the constraint: Num (i -> a -> [a])
    (Use FlexibleContexts to permit this)
   When checking that ‘it’ has the inferred type
      it :: forall i a a1.
            (Num i, Num a1, Num (i -> a -> [a]), Num (a1 -> i -> a -> [a]),
             Ord i) =>
            i -> a -> [a]

I get the following error message.How can I make it work for negative numbers?
Why do we need (Num a,Ord a) constraint? 

A:

Surround the negative number with parentheses i.e. myreplica (-1) 123. However, you might instead want to add a special case using error for negative numbers in first argument, since it doesn't make sense to repeat something a negative number of times.
Demo

