1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Rep Power

    [ML] Error use filter, isupper and string.sub

    fun only_capitals (sl : string list) = let fun g (x) = Char.isUpper(String.sub(x, 0)) in List.filter (g, sl) end;
    I've tried various ways to set this up to get only the strings (starting) with capital letters but I can't figure out a way to do it.

    This version is the closes I've come but I'm getting this error:

    HW3.sml:38.9-38.28 Error: operator and operand don't agree [tycon mismatch]
    operator domain: 'Z -> bool
    operand: (string -> bool) * string list
    in expression:
    List.filter (g,sl)
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2007
    Rep Power
    I don't know any Standard ML, but from the error message it looks like the syntax List.filter(g,sl) is applying List.filter to a 2-Tuple (g,sl) instead of applying it first to g, then to sl. Have you checked whatever reference you're using for the syntax when calling a function that takes multiple arguments (or example of List.filter in general)?

    Comments on this post

    • sepp2k1 agrees : Yes, that's exactly the problem.
    sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);

IMN logo majestic logo threadwatch logo seochat tools logo