Hello, I am wondering how to map functions in sml or Metalanguage. I would like
ID: 3615024 • Letter: H
Question
Hello, I am wondering how to map functions in sml or Metalanguage. I would like to apply the concatanation function toevery element like thismap (op :: ) (which doesn't work)
I was thinking I could do something like this...
fun xa (a, b)= a::b;
fun mm(a) = map xa;
but I get a wierd error
- mm [[1,2,3], [8, 9 , 10], [23]];
stdIn:54.1-54.32 Warning: type vars not generalized because of
value restriction are instantiated to dummy types(X1,X2,...)
val it = fn : (?.X1 * ?.X1 list) list -> ?.X1 list list
- mm ([1,2,3], [8, 9 , 10], [23]);
stdIn:55.1-55.32 Warning: type vars not generalized because of
value restriction are instantiated to dummy types(X1,X2,...)
val it = fn : (?.X1 * ?.X1 list) list -> ?.X1 list list
Any ideas about how to go about doing this?
Thanks in advance for any input.
Explanation / Answer
//Hope this will helpyou.
- fun map f = fn[] => [] | (x::xs) => f x ::map f xs; val map = fn : ('a -> 'b) -> 'a list -> 'b list - f([1,2,3]); val it = [2,3] : int list - - fun map f = fn[] => [] | (x::xs) => f x ::map f xs; val map = fn : ('a -> 'b) -> 'a list -> 'b list - f([1,2,3]); val it = [2,3] : int list -
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.