88-- Allow us to use string literals for Text
99{-# LANGUAGE OverloadedStrings #-}
1010
11+ -- Allow us to display a target type.
12+ {-# LANGUAGE TypeApplications #-}
13+
1114module Graphics.Implicit.ExtOpenScad.Util.ArgParser (
1215 argMap ,
1316 argument ,
@@ -40,6 +43,8 @@ import Data.Maybe (isNothing, fromJust, isJust)
4043
4144import Data.Text.Lazy (Text , pack , unpack )
4245
46+ import Type.Reflection (Typeable , typeRep )
47+
4348import Control.Arrow (first )
4449
4550-- * ArgParser building functions
@@ -48,7 +53,7 @@ import Control.Arrow (first)
4853
4954-- | Builds an argparser for the type that is expected from it.
5055-- FIXME: make a version of this that accepts multiple symbol names, so we can have h= and height=
51- argument :: forall desiredType . (OTypeMirror desiredType ) => Symbol -> ArgParser desiredType
56+ argument :: forall desiredType . (OTypeMirror desiredType , Typeable desiredType ) => Symbol -> ArgParser desiredType
5257argument name =
5358 AP name Nothing " " $ \ oObjVal -> do
5459 let
@@ -58,7 +63,9 @@ argument name =
5863 errmsg = case oObjVal of
5964 OError err -> " error in computing value for argument " <> pack (show name)
6065 <> " : " <> err
61- _ -> " arg " <> pack (show oObjVal) <> " not compatible with " <> pack (show name)
66+ _ -> " arg " <> pack (show name) <>
67+ " expected " <> pack (show $ typeRep @ desiredType ) <>
68+ " but found " <> oTypeStr oObjVal
6269 maybe (APFail errmsg) APTerminator val
6370{-# INLINABLE argument #-}
6471
0 commit comments