How to tell haskell that 'a' is 'a' ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to tell haskell that 'a' is 'a' ?

Lai Boon Hui
Hi all,

skips :: [a] -> [[a]]
skips xs = go 1 [] where
  go :: Int -> [[a]] -> [[a]] -- Compiles if i remove this line
  go n acc
    | n > (length xs) = acc
    | n == 1 = xs : (go (n+1) acc)
    | n < 1 = []
    | otherwise = (everyN n xs) : (go (n+1) acc)

everyN :: Int -> [a] -> [a]
everyN n xs =
  case (drop (n-1) xs) of
    y:ys -> y : (everyN n ys)
    [] -> []

How can i tell haskell compiler that a is the sub program if the same as a in the main program?


--
Best Regards,
Boon Hui

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: How to tell haskell that 'a' is 'a' ?

Sylvain Henry-2

Hi,

Use ScopedTypeVariables and forall:

{-# LANGUAGE ScopedTypeVariables #-}

skips :: forall a. [a] -> [[a]]
skips xs = go 1 [] where
   go :: Int -> [[a]] -> [[a]]
   ...

Sylvain

On 14/11/2016 03:15, Lai Boon Hui wrote:
Hi all,

skips :: [a] -> [[a]]
skips xs = go 1 [] where
  go :: Int -> [[a]] -> [[a]] -- Compiles if i remove this line
  go n acc
    | n > (length xs) = acc
    | n == 1 = xs : (go (n+1) acc)
    | n < 1 = []
    | otherwise = (everyN n xs) : (go (n+1) acc)

everyN :: Int -> [a] -> [a]
everyN n xs =
  case (drop (n-1) xs) of
    y:ys -> y : (everyN n ys)
    [] -> []

How can i tell haskell compiler that a is the sub program if the same as a in the main program?


--
Best Regards,
Boon Hui


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners