[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-beginners
Subject:    Re: [Haskell-beginners] A simple function
From:       Lyndon Maydwell <maydwell () gmail ! com>
Date:       2012-08-30 13:17:54
Message-ID: CAM5QZtybfbjOSYXuXdes2GdO6ZAhvD6c5b5xtdyT6LtK5+C_Og () mail ! gmail ! com
[Download RAW message or body]

Probably the easiest way to ensure this at compile time would be to
use tuples for the arguments:

intercalate :: (t,t) -> (t,t)->[t]

And for the result too, if you care about the length of it:

intercalate :: (t,t) -> (t,t) -> (t,t,t,t)

There are certain packages that allow for size-indexed list-like types
such as HList and Data.Vec, although these are usually considered as
not terribly beginner friendly due to type-encoded naturals, etc.

Is there a particular reason why you want to create such an
intercalate function? It might help with suggesting an approach.

On Thu, Aug 30, 2012 at 8:52 PM, Ezequiel Hernan Di Giorgi
<hernan.digiorgi@gmail.com> wrote:
> Hallo liebe Leute. Hola gente. I'm starting with Haskell and i have some
> problems:
>
> intercalate :: [t] -> [t] -> [t]
> intercalate [a,b] [c,d] = [a,c,b,d]
> intercalate (_) (_) = error "JOJO u cant do this"
>
>
> Are there any form to restrict the parmaters that only allow to call the
> function intercalate with two arrays of two elements, in compilation time?
> Cause i cant write intercalete :: [t,t] -> [t,t]->[t,t,t,t].
>
> Sorry for my bad english. I'm Argentinean.
>
> Thanks!
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic