[Haskell-beginners] A simple function
Lyndon Maydwell
maydwell at gmail.com
Thu Aug 30 15:17:54 CEST 2012
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 at 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 at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
More information about the Beginners
mailing list