haskell - What does [a] stand for exactly? -


i'm doing exercises "real world haskell". 1 design safe version of init :: [a] -> [a].

i'm supposed start safeinit :: [a] -> maybe [a]

this have @ moment.

safeinit :: [a] -> maybe [a] safeinit [] = nothing safeinit [a] = if length [a] <= 1     nothing     else (take (length [a] -1) [a]) 

in gchi, when testing safeinit [1,2] error message

* exception: ch4exercise.hs:(21,1)-(24,44): non-exhaustive patterns in function safeinit

i under impression [a] stands list (of size) of a's. doing wrong?

as type, [a] stand "a list of size of as". pattern however, [a] stands "a list containing 1 element, shall henceforth known name a". [a,b] mean "a list containing 2 elements, first of shall known a , second of shall known b" , so. [], seem know, stands "a list containing 0 elements".

this analogous how you'd write list literals expressions. i.e. if write mylist = [], mylist empty list , if write mylist = [x], mylist list containing 1 element, value of variable x.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -