-
Notifications
You must be signed in to change notification settings - Fork 255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error occurs when apply first into empty list #275
Comments
Returning a |
It indeed is an awkward case in Python, in Clojure since |
I have a pr here to make handling exceptions easier: #262 |
You're not the first one coming from Clojure to find the usage of @boathit, would |
Yeah, it would be helpful, thanks. Additionally, the suggestion that defining a |
Maybe I am biased from other languages but I think that there is no singleton value you can define that will not be ambigious. $ ghci
λ> head []
*** Exception: Prelude.head: empty list
λ> import Data.Maybe (listToMaybe)
λ> listToMaybe []
Nothing
λ> listToMaybe [1]
Just 1 $ sml
- hd [];
stdIn:1.2-1.7 Warning: type vars not generalized because of
value restriction are instantiated to dummy types (X1,X2,...)
uncaught exception Empty
raised at: smlnj/init/pervasive.sml:209.19-209.24
- open List;
[autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[autoloading done]
opening List
datatype 'a list = :: of 'a * 'a list | nil
exception Empty
val null : 'a list -> bool
val hd : 'a list -> 'a
val tl : 'a list -> 'a list
val last : 'a list -> 'a
val getItem : 'a list -> ('a * 'a list) option
val nth : 'a list * int -> 'a
val take : 'a list * int -> 'a list
val drop : 'a list * int -> 'a list
val length : 'a list -> int
val rev : 'a list -> 'a list
val @ : 'a list * 'a list -> 'a list
val concat : 'a list list -> 'a list
val revAppend : 'a list * 'a list -> 'a list
val app : ('a -> unit) -> 'a list -> unit
val map : ('a -> 'b) -> 'a list -> 'b list
val mapPartial : ('a -> 'b option) -> 'a list -> 'b list
val find : ('a -> bool) -> 'a list -> 'a option
val filter : ('a -> bool) -> 'a list -> 'a list
val partition : ('a -> bool) -> 'a list -> 'a list * 'a list
val foldr : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b
val foldl : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b
val exists : ('a -> bool) -> 'a list -> bool
val all : ('a -> bool) -> 'a list -> bool
val tabulate : int * (int -> 'a) -> 'a list
val collate : ('a * 'a -> order) -> 'a list * 'a list -> order
- getItem [];
stdIn:2.1-2.11 Warning: type vars not generalized because of
value restriction are instantiated to dummy types (X1,X2,...)
val it = NONE : (?.X1 * ?.X1 list) option
- getItem [1];
val it = SOME (1,[]) : (int * int list) option |
I agree with @llllllllll here. I think that it's idiomatic in Python to get a The Python language doesn't have such a singleton and I think that it's beyond scope for |
Well, thanks you guys insightful argument. |
Both
first([])
andfirst('')
will throw an error, should it be more reasonable to return aNone
when the list is empty?The text was updated successfully, but these errors were encountered: